Node.js Articles

Page 10 of 22

Node.js - process.traceDeprecation() Method

Mayank Agarwal
Mayank Agarwal
Updated on 17-Jan-2022 3K+ 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
Mayank Agarwal
Updated on 17-Jan-2022 244 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
Mayank Agarwal
Updated on 17-Jan-2022 2K+ 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

How to exit a process in Node.js?

Mayank Agarwal
Mayank Agarwal
Updated on 17-Jan-2022 11K+ 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
Mayank Agarwal
Updated on 17-Jan-2022 242 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
Mayank Agarwal
Updated on 17-Jan-2022 159 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
Mayank Agarwal
Updated on 17-Jan-2022 11K+ 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

Node.js - diffieHellman.computeSecret() Method

Mayank Agarwal
Mayank Agarwal
Updated on 17-Jan-2022 320 Views

The diffieHellman.computeSecret() is used for computing the shared secret using the public key of other's party and returning the computed shared secret. The suppliedKey is interpreted using the specified inputEncoding and the secret is encoded using the specified outputEncoding. If the inputEncoding is not specified the other publicKey is expected to be a buffer, DataView.SyntaxdiffieHellman.computeSecret(otherPublicKey, [inputEncoding], [outputEncoding])ParametersotherPublicKey – This is the public key that is used to compute the secret.inputEncoding – This encoding is used to interpret the supplied key.outputEncoding – This encoding is used for encoding the computed secret value.Example 1Create a file with the name "computeSecret.js" and copy ...

Read More

Node.js – Timers Module – Cancelling Timers

Mayank Agarwal
Mayank Agarwal
Updated on 24-Nov-2021 525 Views

A timer can only be cancelled after it is being scheduled. The Immediate class has an object for setImmediate() method and passes the same object to clearImmediate(), in case it wants to cancel the scheduled timer function.Scheduling TimersThis type of timers schedules the task to take place after a certain instant of time.setImmediate()setInterval()setTimeout()Cancelling TimersThis type of timers cancels the scheduled tasks which is set to take place.ClearImmediate()clearInterval()clearTimeout()1. clearImmediate() methodThis method clears the Immediate timer object that is created by the setImmediate() method.SyntaxclearImmediate( timer )Examplefilename - clearImmediate.js// clearImmediate() Example var timer = setImmediate(function A() {    console.log("Timer set"); }); ...

Read More

Using Redis Cache with Spring Boot

Mayank Agarwal
Mayank Agarwal
Updated on 24-Nov-2021 6K+ Views

In this article, we will see how to integrate Redis Cache with Spring Boot. We will learn how we can configure Redis data inside the Spring boot cache.Let's look at the dependencies first that are required to import Redis into a Spring boot application.Dependencies// Adding spring-boot cache & redis dependencies    org.springframework.boot    spring-boot-starter-cache    2.4.3    org.springframework.boot    spring-boot-starter-data-redis    2.4.3 ConfigurationAfter adding the Redis dependencies, you now need to perform some configuration so that it could be used in your project. Spring Boot will automatically configure a Redis-cache Manager but with default properties. We can ...

Read More
Showing 91–100 of 212 articles
« Prev 1 8 9 10 11 12 22 Next »
Advertisements