Javascript Articles - Page 129 of 534
5K+ Views
The send() and json() functions are used for sending the response to the client directly from the server. The send() method will send the data in a string format, whereas the json() function will send the same in JSON format. The sendStatus() method is used for sending the HTTP request status with the client. Possible status values are: 200(Success), 404(Not found), 201(Created), 503(Server Unreachable) etc.PrerequisiteNode.jsExpress.jsInstallationInstall the express module using the below statement −npm install expressExample - sendStatus()Create a file with name – sendStatus.js and copy the below code snippet. After creating file, use the following command to run this code ... Read More
217 Views
The script.createCachedData() method is used for creating a code cache that will be used along with the cachedData option of the script constructor. This cachedData can be called multiple number of times without latency. This method is an inbuilt programming interface from the 'script' module.Syntaxscript.createCachedData()ParametersSince it only caches the data. It does not require any specific inputs from the user. It only returns the cached buffer.ExampleCreate a file with name – createCachedData.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node createCachedData.jscreateCachedData.js// Node.js program to ... Read More
6K+ Views
We can read a text file and return its content as an Array using node.js. We can use this array content to either process its lines or just for the sake of reading. We can use the 'fs' module to deal with the reading of file. The fs.readFile() and fs.readFileSync() methods are used for the reading files. We can also read large text files using this method.Example (Using readFileSync())Create a file with name – fileToArray.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node fileToArray.jsfileToArray.js// ... Read More
531 Views
The process.argv() method is used for getting the user environment object. This object will contain all the information about the environment on which this command is being executed.Syntaxprocess.env()ParametersSince it returns an object for the user environment. It does not need any inputs from the user as such.ExampleCreate a file with name – env.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node env.jsenv.js Live Demo// Node.js program to demonstrate the use of process.env // Importing the process module const process = require('process'); // Printing ... Read More
1K+ Views
The process.argv() method is used for getting the user and its cpu usage for the current running process. The data is returned in an object with the properties user and system. The values obtained are in microseconds, i.e.10^-6 seconds. The values returned may be greater than the actual elapsed time if multiple cores are performing work for the running process.Syntaxprocess.cpuUsage([previousValue])ParametersThe method only accepts a single parameter which is defined below −previousValue – This is an optional parameter. This is the previous return value by calling the process.cpuUsage() method.ExampleCreate a file with name – cpuUsage.js and copy the below code snippet. After ... Read More
7K+ Views
The process.chdir() method is used for changing the current directory of the Node.js process. It will throw an exception if any error occurs or the process fails, but will not return any response on success. For Example: It can fail when the specified directory does not exist.Syntaxprocess.chdir(directory)Parametersdirectory – This will contain the name of the directory that will be updated in place of earlier directory name.ExampleCreate a file with name – chdir.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below &Minus;node chdir.jschdir.js Live Demo// Node.js program to ... Read More
5K+ Views
The process.argv() method is used for returning all the command-line arguments that were passed when the Node.js process was being launched. The first element will always contains the same value as process.execPath.Syntaxprocess.argv()ParametersSince it returns all the command line arguments passed before the node.js process. It does not need any inputs from the user.ExampleCreate a file with name – argv.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −node argv.jsargv.js Live Demo// Node.js program to demonstrate the use of process.argv // Importing the process module const ... Read More
441 Views
The decipher.update() is used to update the decipher with the receivd data according to the given encoding format. It is one of the inbuilt method that is provided by the class Decipher within the crypto module. If an input encoding is specified, the data argument is a string, else the data argument is a bufferSyntaxdecipher.update(data, [inputEncoding], [outputEncoding])ParametersThe above parameters are described as below −data – It takes the data as an input that is passed to update the decipher content.inputEncoding – It takes the input encoding as a parameter. Possible input values are hex, base64, etc.outputEncoding – It takes the output encoding as ... Read More
413 Views
The decipher.final() is used to return a buffer or string containing the value of decipher object. It is one of the inbuilt method that is provided by the class Cipher within the crypto module. The decipher method cannot be used to decrypt data once the decipher.final method has been called. Calling the cipher.final method more than once will throw an error.Syntaxdecipher.final([outputEncoding])ParametersThe above parameters are described as below −outputEncoding – It takes the output encoding as a parameter. The input type for this parameter is string. Possible input values are hex, base64, etc.ExampleCreate a file with name – decipherFinal.js and copy the ... Read More
861 Views
The crypto.scrypt() method provides an asynchronous implementation for scrypt method. The scrypt can be defined as a password-based key derivation function that protects the system from the brute-force attacks and makes it unawarding. But the script function is expensive computationally as well as memory-wise.Syntaxcrypto.scrypt(password, salt, keylen, [options], [callback])ParametersThe above parameters are described as below −password – The password field for the scrypt required to decode entry. It can be a string, object, TypedArray, etc.salt – This value should be as unique as possible. This is mainly used for encrypting the data. The minimum suggested length of salt is 16 bytes.keylen – This parameter ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP