Found 285 Articles for Node.js

Node.js - dns.resolve6() Method

Mayank Agarwal
Updated on 17-Jan-2022 12:19:50

110 Views

The dns.resolve6() method uses the DNS protocol to resolve the IPv6 addresses (AAAA records) for the hostname. The addresses argument that is passed to the callback will contain an array of IPv6 addresses.Syntaxdns.resolve6(hostname, [options], callback)Parametershostname – This parameter takes the input for the hostname to be resolved.options – It can have the following options −ttl – This defines the Time-To-Live (TTL) for each record.Example 1Create a file with the name "resolve6.js" and copy the following code snippet. After creating the file, use the command "node resolve6.js" to run this code as shown in the example below −// dns.resolve6() Demo Example ... Read More

Node.js - diffieHellman.getPrivateKey() Method

Mayank Agarwal
Updated on 17-Jan-2022 12:13:49

90 Views

The diffieHellman.getPrivateKey() returns the Diffie-Hellman generated private key that is specified by the encoding passed. A string is returned in case if encoding is passed, else a buffer will be returned.SyntaxdiffieHellman.getPrivateKey( [encoding] )where, encoding is the parameter that specifies the encoding of the return value.Example 1Create a file with the name "privateKey.js" and copy the following code snippet. After creating the file, use the command "node privateKey.js" to run this code as shown in the example below −// diffieHellman.getPriateKey() Demo Example // Importing the crypto module const crypto = require( 'crypto' ) // Initializing the diffieHellman const dh = ... Read More

Node.js - process.traceDeprecation() Method

Mayank Agarwal
Updated on 17-Jan-2022 12:02:29

2K+ Views

This process.traceDeprecation() method states whether the --trace-deprecation flag is set or not on the current Node.js project. This Boolean flag controls whether the trace of deprecation warning messages are printed or not.Syntaxprocess.traceDeprecation( )Example 1Create a file with the name "traceDeprecation.js" and copy the following code snippet. After creating the file, use the command "node traceDeprecation.js" to run this code as shown in the example below −// process.traceDeprecation() Demo Example // Importing the process module const process = require('process'); // Printing traceDeprecation default value console.log(process.traceDeprecation);Output 1C:\homeode>> node traceDeprecation.js undefinedOutput 2C:\homeode>> node --trace-deprecation traceDeprecation.js trueExample 2// process.traceDeprecation() Demo Example ... Read More

Node.js - dnsPromises.resolveNs() Method

Mayank Agarwal
Updated on 17-Jan-2022 11:58:34

90 Views

The dnsPromises.resolveNs() method uses the DNS protocol to resolve the name server records (NS) for the hostname. On success, the promise is resolved with an array of name server records available for the hostname.SyntaxdnsPromises.resolveNs( hostname )where hostname is the parameter that takes the input for the hostname to be resolved.Example 1Create a file with the name "resolveNs.js" and copy the following code snippet. After creating the file, use the command "node resolveNs.js" to run this code as shown in the example below −// dns.resolveNs() Demo Example // Importing the dns module const dns = require('dns'); const dnsPromises = ... Read More

Node.js - dns.reverse() Method

Mayank Agarwal
Updated on 17-Jan-2022 11:53:57

1K+ Views

The dns.reverse() method is somewhat opposite of the method dns.lookup().This method performs a reverse DNS query that resolves an IPv4 or IPv6 to an array of host names.Syntaxdns.reverse(ip, callback)Parametersip – This takes an input for ip as a string, for which the DNS needs to be found.callback – It will catch errors, if any.Example 1Create a file with the name "reverse.js" and copy the following code snippet. After creating the file, use the command "node reverse.js" to run this code as shown in the example below −// dns.reverse() method Demo Example // Importing the dns module const dns = ... Read More

Node.js - clent.hgetall & client.hmset in Redis

Mayank Agarwal
Updated on 17-Jan-2022 11:47:52

2K+ Views

Redis commands mostly take the input as a single string or an array of strings as arguments and the replies are sent back as a single string or an array of strings. But, while dealing with the hash values, there are a couple of exceptions.The client.hgetall() function in Node.js – Redis returns an Object keyed by the Hash keys. The strings will be returned either as a string or as a buffer depending upon the setting.The client.hmset() function supplies the Hash arguments to Redis.Syntaxclient.hmset()client.hmset(hash, key1, val1, ...keyN, valN, [callback])client.hgetall()client.hgetall(hash, callback)Example 1Create a file with the name "hmset.js" and copy the ... Read More

How to exit a process in Node.js?

Mayank Agarwal
Updated on 17-Jan-2022 11:42:16

9K+ Views

There are some cases where we need to exit a certain process in Node.js based upon a condition. For this condition, we have the following methods where we can escape or exit any Node.js Process.Method 1: Using the Ctrl+C keyI hope everyone knows this shortcut to exit any Node.js process from outside. This shortcut can be used to stop any running process by hitting this command on terminal.Method 2: Using the process.exit() functionThis function instructs Node.js to end the process that is running at an instant with an exit code. Node.js will force the current running process to stop execution ... Read More

Node.js – dnsPromises.reverse() Method

Mayank Agarwal
Updated on 17-Jan-2022 11:35:55

99 Views

The dnsPromises.reverse() method performs a reverse DNS search to resolve the IPv4 or Ipv6 address to an array of hostnames. The promise is rejected with an Error object if a Success status is not encountered.SyntaxdnsPromises.reverse( ip )where, ip is the parameter that takes the input for the IP address to be resolved.Example 1Create a file with the name "reverse.js" and copy the following code snippet. After creating the file, use the command "node reverse.js" to run this code as shown in the example below −// dns.reverse() Demo Example // Importing the dns module const dns = require('dns'); const ... Read More

Node.js – dns.resolveSoa() Method

Mayank Agarwal
Updated on 17-Jan-2022 11:30:06

55 Views

The dns.resolveSoa() method uses the DNS protocol to resolve the start of authority records for the hostname. The address argument passed to the callback function will be an object that will contain the following properties −nsnamehostmasterserialrefreshentryexpireSyntaxdns.resolveSoa(hostname, callback)ParametersIt accepts the following parameters −hostname – This parameter takes the input for the hostname to be resolved.callback – This function will catch errors, if any.records – Returns the start of authority records for the hostname.ExampleCreate a file with the name "resolveSoa.js" and copy the following code snippet. After creating the file, use the command node "resolveSoa.js" to run this code as shown in ... Read More

How to download a file using Node.js?

Mayank Agarwal
Updated on 17-Jan-2022 11:23:34

9K+ Views

We can download file using Node.js by either using third-party libraries or using some inbuilt packages.Method 1: Using 'https' and 'fs' moduleWe can use the http GET method to fetch the files that are to be downloaded.The createWriteStream() method from fs module creates a writable stream and receives the argument with the location of the file where it needs to be saved.pipe() is another method from fs that reads the data from the readable stream and writes it onto the writable stream and file.Example 1Create a file with the name downloadFile.js and copy the following code snippet. After creating the ... Read More

Advertisements