Node.js Timer9 Dec 2024 | 2 min read Node.js Timer functions are global functions. You don't need to use require() function in order to use timer functions. Let's see the list of timer functions. Set timer functions:
Clear timer functions:
Node.js Timer setInterval() ExampleThis example will set a time interval of 1000 millisecond and the specified comment will be displayed after every 1000 millisecond until you terminate. File: timer1.js Open Node.js command prompt and run the following code: ![]() File: timer5.js Open Node.js command prompt and run the following code: ![]() Node.js Timer setTimeout() ExampleFile: timer1.js Open Node.js command prompt and run the following code: ![]() This example shows time out after every 1000 millisecond without setting a time interval. This example uses the recursion property of a function. File: timer2.js Open Node.js command prompt and run the following code: ![]() Node.js setInterval(), setTimeout() and clearTimeout()Let's see an example to use clearTimeout() function. File: timer3.js Open Node.js command prompt and run the following code: ![]() You can see that the above example is recursive in nature. It will terminate after one step if you use ClearInterval. Node.js setInterval(), setTimeout() and clearInterval()Let's see an example to use clearInterval() function. File: timer3.js Open Node.js command prompt and run the following code: ![]() Next TopicNode.js Errors |
The Node.js path module is used to handle and transform files paths. This module can be imported by using the following syntax: Syntax: var path = require ("path") Methods Let's see the list of methods used in path module: Index Method Description 1. path.normalize(p) It is used to normalize a string path, taking care...
2 min read
Callback is an asynchronous equivalent for a function. It is called at the completion of each task. In Node.js, callbacks are generally used. All APIs of Node are written in a way to supports callbacks. For example: when a function start reading file, it returns the...
2 min read
Node.js provides a simple TCP based protocol and built-in debugging client. For debugging your JavaScript file, you can use debug argument followed by the js file name you want to debug. Syntax: node debug [script.js | -e "script" | <host>:<port>] Example: node debug main.js If you make any error: If you...
1 min read
The Node.js applications generally face four types of errors: Standard JavaScript errors i.e. <EvalError>, <SyntaxError>, <RangeError>, <ReferenceError>, <TypeError>, <URIError> etc. System errors User-specified errors Assertion errors Example 1 Let's take an example to deploy standard JavaScript error - ReferenceError. File: error_example1.js // Throws with a ReferenceError because b is undefined try { ...
1 min read
Streams are the objects that facilitate you to read data from a source and write data to a destination. There are four types of streams in Node.js: Readable: This stream is used for read operations. Writable: This stream is used for write operations. Duplex: This stream can be...
3 min read
Node.js provides Buffer class to store raw data similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. Buffer class is used because pure JavaScript is not nice to binary data. So, when dealing with TCP streams or...
2 min read
The is used to decode buffer into string. It is similar to buffer.toString() but provides extra support to UTF. You need to use require('string_decoder') to use StringDecoder module. const StringDecoder = require('string_decoder').StringDecoder; Methods StringDecoder class has two methods only. Method Description decoder.write(buffer) It is used to return the decoded string. decoder.end() It is...
1 min read
The module supports cryptography. It provides cryptographic functionality that includes a set of wrappers for open SSL's hash HMAC, cipher, decipher, sign and verify functions. What is Hash A hash is a fixed-length string of bits i.e. procedurally and deterministically generated from some arbitrary block of...
1 min read
(FS) In Node.js, file I/O is provided by simple wrappers around standard POSIX functions. Node File System (fs) module can be imported using following syntax: Syntax: var fs = require("fs") Node.js FS Reading File Every method in fs module has synchronous and asynchronous forms. Asynchronous methods take a last...
3 min read
There can be console-based and web-based node.js applications. Node.js console-based Example File: console_example1.js console.log('Hello JavaTpoint'); Open Node.js command prompt and run the following code: node console_example1.js Here, console.log() function displays message on console. Node.js web-based Example A node.js web application contains the following three parts: Import required modules: The first step is to...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India