Node.js Interview Questions & Answers

1. What is node.js  

Short Answer

Node.js is a Server side scripting which is used to build scalable programs. Its multiple advantages over other server side languages, the prominent being non-blocking I/O.

Long Answer

Node.js is a server-side technology that’s based on Google’s V8 JavaScript engine. It’s a highly scalable system that uses asynchronous, event-driven I/O (input/output), rather than threads or separate processes. It’s ideal for web applications that are frequently accessed but computationally simple.

If you’re using a traditional web server, such as Apache, each time a web resource is requested, Apache creates a separate thread or invokes a new process in order to handle the request. Even though Apache responds quickly to requests, and cleans up after the request has been satisfied, this approach can still tie up a lot of resources. A popular web application is going to have serious performance issues.

Node, on the other hand, doesn’t create a new thread or process for every request. Instead, it listens for specific events, and when the event happens, responds accordingly. Node doesn’t block any other request while waiting for the event functionality to complete, and events are handled—first come, first served—in a relatively uncomplicated event loop. Node applications are created with JavaScript (or an alternative language that compiles to JavaScript). The JavaScript is the same as you’d use in your client-side applications. However, unlike JavaScript in a browser, with Node you have to set up a development environment.

Node can be installed in a Unix/Linux, Mac OS, or Windows environment. This chapter will walk you through setting up a development environment for Node in Windows 7 and Linux (Ubuntu). Installation on a Mac should be similar to installation on Linux. I’ll also cover any requirements or preparation you need to take before installing the application. Once your development environment is operational, I’ll demonstrate a basic Node application and walk you through the important bit—the event loop I mentioned earlier.

2. How node.js works  

Short Answer

Node.js works on a v8 environment, it is a virtual machine that utilizes JavaScript as its scripting language and achieves high output via non-blocking I/O and single threaded event loop.

Long Answer

NodeJS is built on top of V8, Google’s Javascript engine that also powers the Chrome browser, which sported the fastest Javascript execution speeds and pretty much put Javascript performance right up in front when it came to comparing browsers, turning speed into a major marketing for browsers.

3. What do you mean by the term I/O ?  

I/O is the shorthand for input and output, and it will access anything outside of your application. It will be loaded into the machine memory to run the program, once the application is started.

4. What does event-driven programming mean?  

In computer programming, event driven programming is a programming paradigm in which the flow of the program is determined by events like messages from other programs or threads.

5. Where can we use node.js?  

Node.js shines in real-time web applications employing push technology over web sockets. It can be used for the following purposes: a) Web applications (especially real-time web apps) b) Network applications c) Distributed systems d) General purpose applications

6. What is the advantage of using node.js?  

It provides an easy way to build scalable network programs a) Easy to install and run locally b) Generally fast c) Great concurrency d) Asynchronous everything e) Almost never blocks f) Unified programming language and data type

7. What are the two types of API functions in Node.js?  

The two types of API functions in Node.js are: a) Asynchronous, non-blocking functions b) Synchronous, blocking functions

8. What is control flow function?  

A generic piece of code which runs in between several asynchronous function calls is known as control flow function.

9. Explain the steps how “Control Flow” controls the functions calls?  

Control the order of execution -> Collect data -> Limit concurrency -> Call the next step in program

10. Why Node.js is single threaded?  

For async processing, Node.js was created explicitly as an experiment. It is believed that more performance and scalability can be achieved by doing async processing on a single thread under typical web loads than the typical thread based implementation.

11. Does node run on windows?  

  • A) No
  • B) yes

12. Can you access DOM in node?  

No, you cannot access DOM in node.

13. Using the event loop what are the tasks that should be done asynchronously?  

a. I/O operations b. Heavy computation c. Anything requiring blocking

14. Why node.js is quickly gaining attention from JAVA programmers?  

Node.js is quickly gaining attention as it is a loop based server for JavaScript. Node.js gives user the ability to write the JavaScript on the server, which has access to things like HTTP stack, file I/O, TCP and databases.

15. What are the two arguments that async.queue takes?  

The two arguments that async.queue takes a) Task function b) Concurrency value

16. What is an event loop in Node.js ?  

To process and handle external events and to convert them into callback invocations an event loop is used. So, at I/O calls, node.js can switch from one request to another .

17. Mention the steps by which you can async in Node.js?  

By following steps you can async Node.js : First class functions -> Function composition -> Callback Counters -> Event loops

18. What are the pros and cons of Node.js?  

  • Pros:
    • a) If your application does not have any CPU intensive computation, you can build it in Javascript top to bottom, even down to the database level if you use JSON storage object DB like MongoDB.
    • b) Crawlers receive a full-rendered HTML response, which is far more SEO friendly rather than a single page application or a websockets app run on top of Node.js.
  • Cons:
    • a) Any intensive CPU computation will block node.js responsiveness, so a threaded platform is a better approach.
    • b) Using relational database with Node.js is considered less favorable.

19. How Node.js overcomes the problem of blocking of I/O operations?  

Node.js solves this problem by putting the event based model at its core, using an event loop instead of threads.

20. What is the difference between Node.js vs Ajax?  

The difference between Node.js and Ajax is that, Ajax (short for Asynchronous Javascript and XML) is a client side technology, often used for updating the contents of the page without refreshing it. While,Node.js is Server Side Javascript, used for developing server software. Node.js does not execute in the browser but by the server.

.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions