The path.join() method is used to join a number of path segments using the platform-specific delimiter to form a single path. The final path is normalized after the joining takes place. The path segments are specified using comma-separated values....
The crypto.generateKeyPair() method is an inbuilt application programming interface of crypto module which is used to generate a new asymmetric key pair of the specified type. For example, the currently supported key types are RSA, DSA, EC, Ed25519, Ed448, X25519, X448, and DH. Moreover, if option’s publicKeyEncoding or privateKeyEncoding is stated here, then this function acts as if keyObject.export() had been called on its output. Else, the particular part of the key is returned as a KeyObject.
However, it is suggested to encode the public keys as ‘spki’ and private keys as ‘pkcs8’ with encryption for long-term storage....
The querystring.stringify() method is used to produce an URL query string from the given object that contains the key-value pairs. The method iterates through the object’s own properties to generate the query string....
The process.hrtime() method to measure code execution time which returns an array that includes current high-resolution real-time in [seconds, nanoseconds]. We measure the code execution time by providing the time returned by the first process.hrtime() call as a parameter in the second process.hrtime() call....
File-writing is an important aspect of programming. Every programming language has a well-defined file module that can be used to perform file operations. JavaScript and Node.js also have file module which provides various inbuilt methods for performing read, write, rename, delete and other operations on files. The file module of Node.js is called the fs module. By default, the fs module writes files with an encoding of ‘UTF-8’....
The fs.promise.readdir() method defined in the File System module of Node.js. The file System module is basically to interact with the hard disk of the users computer. The readdir() method is used to read the files and folders names. The fs.promise.readdir() method returns a resolved or rejected promise and hence avoid the callback nesting or callback hell problems that may occur in fs.readdir() method....
The fs.watch() method is an inbuilt application programming interface of fs module which is used to continuously watch for changes in the given file or directory. It returns a fs.FSWatcher object that can be used to track the changes in the file....
The fs.renameSync() method is used to synchronously rename a file at the given old path to the given new path. It will overwrite the destination file if it already exists....
The crypto.randomUUID() is an inbuilt application programming interface of class Crypto within crypto module which is used to generate a random RFC 4122 Version 4 UUID....
Node.js is used for server-side scripting. Reading and writing files are the two most important operations that are performed in any application. Node.js offers a wide range of inbuilt functionalities to perform read and write operations. The fs package contains the functions required for file operations. The read() method of the fs package reads the file using a file descriptor. In order to read files without file descriptors the readFile() method of the fs package can be used....
Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside the browser. It is widely used in developing APIs and microservices from small to large companies....
The fs.rm() method is used to delete a file at the given path. It can also be used recursively to remove directories....