NodeJS Questions
Warm up for your NodeJS interview with most asked questions and answers for junior, mid, and senior roles.
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.