Node.js Interview Questions & Answers



21. What are the Challenges with Node.js?  

Emphasizing on the technical side, it’s a bit of challenge in Node.js to have one process with one thread to scale up on multi core server.


22. What does it mean “non-blocking” in node.js?  

In node.js “non-blocking” means that its IO is non-blocking. Node uses “libuv” to handle its IO in a platform-agnostic way. On windows, it uses completion ports for unix it uses epoll or kqueue etc. So, it makes a non-blocking request and upon a request, it queues it within the event loop which call the JavaScript ‘callback’ on the main JavaScript thread.


23. What is the command that is used in node.js to import external libraries?  

Command “require” is used for importing external libraries, for example, “var http=require (“http”)”. This will load the http library and the single exported object through the http variable.


24. Mention the framework most commonly used in node.js?  

“Express” is the most common framework used in node.js



25. What is ‘Callback’ in node.js?  

Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don’t want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.


26. How Does Node Differ From Other Frameworks?  

The major difference between Node and other server-side technologies is Node’s use of a single thread and asynchronous architecture. Many other server-side technologies are multi-threaded and synchronous, meaning that threads can be blocked while waiting for replies from the database. Each request creates a new thread from a limited pool based on system RAM usage. Node’s asynchronous design allows it to handle a large number of concurrent connections with high throughput on a single-thread, which makes it highly scalable. Node is not meant as a replacement for other technology stacks, but it can provide scalability and increased performance to applications which fit its purpose. Some examples of application types which can benefit from using Node are REST APIs, Chat applications and Real-Time Tracking applications (Brokerage trading dashboards, real-time user statistics, etc.) Node’s homepage describes it as “lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.” The applications above fit that description well and can take advantage of Node’s features.


27. In which language Node.js is written?  

C,C++, javaScript.


28. How to get Post Data in Node.js?  

app.use(express.bodyParser(); app.post('/', function(request, response){ console.log(request.body.user); });


29. How to make Post request in Node.js?  

var request = require('request');
request.post('http://www.example.com/action',
    { form: { key: 'value' } },
    function (error, response, body) {
    if (!error && response.statusCode == 200) {
    console.log(body)
    }
    }
);


30. What is callback hell?  

Callback hell refers to heavily nested callbacks that have become unreadable


31. How to handle the "Unhandled exceptions" in Node.js?  

Process.on('uncaughtException', function(err)
 {
  console.log('Caught exception: ' + err);
});


32. Can you explain how Nodejs works  

It uses Google V8 Javascript engine to execute code. It contains built-in asynchronous I/O library for file, socket and HTTP communication. Node.js encapsulates libuv to handle asynchronous events.


33. Can you explain what is Globals in Nodejs?  

Global, Process and Buffer are combinedly termed as Globals.

Global : Its a global namespace object
Process : Its also a global object but it provides essential functionality to transform a synchronous function into a asynchronous
callback. Buffer : Raw data is stored in instances of the Buffer class.


34. What is the Use of underscore in Nodejs?  

To access the last expression, we have to use the (_) underscore/underline character.


35. What does it mean “non-blocking” in node.js?  

In node.js “non-blocking” means that its IO is non-blocking. Node uses “libuv” to handle its IO in a platform-agnostic way. On windows, it uses completion ports for unix it uses epoll or kqueue etc. So, it makes a non-blocking request and upon a request, it queues it within the event loop which call the JavaScript ‘callback’ on the main JavaScript thread.



36. What is the command that is used in node.js to import external libraries?  

Command “require” is used for importing external libraries, for example, “var http=require (“http”)”. This will load the http library and the single exported object through the http variable.


37. Mention the framework most commonly used in node.js?  

“Express” is the most common framework used in node.js


38. What is ‘Callback’ in node.js?  

Callback function is used in node.js to deal with multiple requests made to the server. Like if you have a large file which is going to take a long time for a server to read and if you don’t want a server to get engage in reading that large file while dealing with other requests, call back function is used. Call back function allows the server to deal with pending request first and call a function when it is finished.



39. Can you create Http Server in Nodejs, explain with code?  

Yes, we can create Http Server in Nodejs. We can use http-server command to do so.
Code :
var http = require('http');
var requestListener = function (request, response) {
  response.writeHead(200, {'Content-Type': 'text/plain'});
  response.end('Hello You\n');
}

var server = http.createServer(requestListener);
server.listen(8080); // The port where you want to start with.


40. How to load HTML in Nodejs?  

To load HTML in Nodejs we have to change the Content-type from text/plain to text/html.


.Net Interview Question

PHP Interview Question

Java Interview Question

AngularJS Interview Questions