NodeJS Questions
Warm up for your NodeJS interview with most asked questions and answers for junior, mid, and senior roles.
What is the role of assert in Node.js?
Show AnswerHide Answer
Assert is a function which is used to check the condition and throw an error if the condition is false.
What is Node.js?
Show AnswerHide Answer
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It is used to build fast, scalable network applications.
Where is Node.js used?
Show AnswerHide Answer
Node. js is primarily used for non-blocking, event-driven servers, due to its single-threaded nature.
What is Express JS?
Show AnswerHide Answer
Express.js is a free and open-source web application framework for Node.js. It is used for designing and building web applications quickly and easily.
How Node.js read the content of a file?
Show AnswerHide Answer
Node.js uses the fs module to read the content of a file.
What is difference between put and patch?
Show AnswerHide Answer
PUT is used to update the existing resource and PATCH is used to update the part of the resource.
What is the use of yarn in Node.js?
Show AnswerHide Answer
Yarn is a package manager. It is used to install and manage dependencies.
What is npm in Node.js?
Show AnswerHide Answer
NPM is a package manager. It is used to install and manage dependencies.
What is difference between JavaScript and Node.js?
Show AnswerHide Answer
JavaScript is a proper high-level programming language used to create web scripts whereas Node. js is a run time environment built on google's v8 engine.
What is Callback function in node.js?
Show AnswerHide Answer
Callback function is a function which is passed as an argument to another function.
What is npm?
Show AnswerHide Answer
npm is a package manager for Node.js. It is used to install and manage packages.
What is the use of EventEmitter in Node.js?
Show AnswerHide Answer
EventEmitter is used to create events and emit events.
The EventEmitter is a module that facilitates communication/interaction between objects in Node. EventEmitter is at the core of Node asynchronous event-driven architecture.
Many of Node's built-in modules inherit from EventEmitter including prominent frameworks like Express.
Does Node.js supports cryptography?
Show AnswerHide Answer
The node:crypto module provides cryptographic functionality that includes a set of wrappers for OpenSSL's hash, HMAC, cipher, decipher, sign, and verify functions.
What are buffers in Node.js?
Show AnswerHide Answer
What is the use of middleware in Node.js?
Show AnswerHide Answer
Middleware is a function that is called before the request is handled by the server. It is used to modify the request and response objects.
What are global objects in Node.js?
Show AnswerHide Answer
Global objects are objects that are available to all modules in Node.js.
Why is assert used in Node.js?
Show AnswerHide Answer
Assert is used to check if a condition is true or false.
What are stubs in Node.js?
Show AnswerHide Answer
Stubs are functions that are used to replace other functions in Node.js.
What are the timing features of Node.js?
Show AnswerHide Answer
- setTimeout() Method: The setTimeout() method is used to schedule code execution after a designated amount of milliseconds.
- setImmediate() Method: The setImmediate() method is used to execute code at the end of the current event loop cycle.
- setInterval() Method: The setInterval() method is used to call a function at specified intervals (in milliseconds). It is used to execute the function only once after a specified period.
Are there any disadvantages to using Node.js?
Show AnswerHide Answer
Some of the disadvantages to using Node.js are:
- Unstable API
- Lack of Library support
- High demand for experienced Resources
- Heavy Computing Tasks
- Asyncronous Programming Model
How can you avoid callbacks?
Show AnswerHide Answer
You can avoid callbacks by using promises.
What are the key features of Node.js?
Show AnswerHide Answer
Asynchronous and Event Driven − All APIs of Node.js library are asynchronous, that is, non-blocking. It essentially means a Node.js based server never waits for an API to return data. The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.
Very Fast − Being built on Google Chrome's V8 JavaScript Engine, Node.js library is very fast in code execution.
Single Threaded but Highly Scalable − Node.js uses a single threaded model with event looping. Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests. Node.js uses a single threaded program and the same program can provide service to a much larger number of requests than traditional servers like Apache HTTP Server.
No Buffering − Node.js applications never buffer any data. These applications simply output the data in chunks.
License − Node.js is released under the MIT license.
What is meant by event-driven programming in Node.js?
Show AnswerHide Answer
Node. js uses event driven programming. It means as soon as Node starts its server, it simply initiates its variables, declares functions and then simply waits for event to occur.
What is JIT and how is it related to Node.js?
Show AnswerHide Answer
Virtual machine of Nodejs has JIT compilation which improves the execution speed of the code. The virtual machine takes the source code and converts to machine code in runtime.
By this, the hot functions which are called very often are compiled to machine code and, hence increasing speed.
What is Libuv?
Show AnswerHide Answer
Libuv is a C library that provides a high-level API for asynchronous I/O. It is used to implement the event loop for Node.js.
What is an event loop in Node.js?
Show AnswerHide Answer
The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded — by offloading operations to the system kernel whenever possible.