Node JS Interview Questions


Q#1. What is Node.js? Where can you use it?

Ans. Node.js is server-side scripting based on Google’s V8 JavaScript engine. It is used to build scalable programs, especially web applications that are computationally simple but are frequently accessed. You can use Node.js in developing I/O intensive web applications like video streaming sites. You can also use it for developing: Real-time web applications, Network applications, General-purpose applications, and Distributed systems.


Q#2. Is Node.js free to use?

Ans. Yes. It is released under MIT license and is free to use.


Q#3. What are the features of Node.js?

Ans. Node.js is a single-threaded but highly scalable system that utilizes JavaScript as its scripting language. It uses asynchronous, event-driven I/O instead of separate processes or threads. It can achieve high output via single-threaded event loop and non-blocking I/O.


Q#4. Is Node a single threaded application?

Ans. Yes. Node is a single-threaded application with event looping.


Q#5. How else can the JavaScript code below be written using Node.Js to produce the same output?

Ans. console.log("first"); setTimeout(function() { console.log("second"); }, 0); console.log("third"); Output: first third second In Node.js version 0.10 or higher, setImmediate(fn) will be used in place of setTimeout(fn,0) since it is faster. As such, the code can be written as follows: console.log("first"); setImmediate(function(){ console.log("second"); }); console.log("third");


Q#6. What is the purpose of Node.js?

Ans. These are the following purposes of Node.js: Real-time web applications Network applications Distributed systems General purpose applications


Q#7. Why is Node.js Single-threaded?

Ans. Node.js is single-threaded for async processing. By doing async processing on a single-thread under typical web loads, more performance and scalability can be achieved as opposed to the typical thread-based implementation.


Q#8. What are the advantages of Node.js?

Ans. Following are the main advantages of Node.js: Node.js is asynchronous and event-driven. All API?s of Node.js library are non-blocking, and its server doesn't wait for an API to return data. It moves to the next API after calling it, and a notification mechanism of Events of Node.js responds to the server from the previous API call. Node.js is very fast because it builds on Google Chrome?s V8 JavaScript engine. Its library is very fast in code execution. Node.js is single threaded but highly scalable. Node.js provides a facility of no buffering. Its application never buffers any data. It outputs the data in chunks.


Q#9. Explain callback in Node.js.

Ans. A callback function is called after a given task. It allows other code to be run in the meantime and prevents any blocking. Being an asynchronous platform, Node.js heavily relies on callback. All APIs of Node are written to support callbacks.


Q#10. What do you understand by the term I/O?

Ans. I/O stands for input and output. It accesses anything outside of your application. It loaded into the machine memory to run the program, once the application starts.