Google News
NodeJS Interview Questions
An event-driven programming approach uses events to trigger various functions. An event can be anything, such as typing a key or clicking a mouse button.
A call-back function already registered with the element executes whenever an event is triggered.
Error-first callbacks in Node.js are used to pass errors and data. The very first parameter you need to pass to these functions has to be an error object while the other parameters represent the associated data. Thus you can pass the error object for checking if anything is wrong and handle it. In case there is no issue, you can just go ahead and with the subsequent arguments.
var myPost = new Post({title: 'freetimelearning'});,myInstance){
       //handle error and return
      //go ahead with `myInstance`
Some of the reasons why Node.js is preferred include:
* Node.js is very fast

* Node Package Manager has over 50,000 bundles available at the developer’s disposal

* Perfect for data-intensive, real-time web applications, as Node.js never waits for an API to return data

* Better synchronization of code between server and client due to same code base

* Easy for web developers to start using Node.js in their projects as it is a JavaScript library
MongoDB is the most common database used with Node.js. It is a NoSQL, cross-platform, document-oriented database that provides high performance, high availability, and easy scalability.
There are two commonly used libraries in Node.js:
* ExpressJS - Express is a flexible Node.js web application framework that provides a wide set of features to develop both web and mobile applications.

* Mongoose - Mongoose is also a Node.js web application framework that makes it easy to connect an application to a database.
Since Node.js is by default a single thread application, it will run on a single processor core and will not take full advantage of multiple core resources. However, Node.js provides support for deployment on multiple-core systems, to take greater advantage of the hardware. The Cluster module is one of the core Node.js modules and it allows running multiple Node.js worker processes that will share the same port.
REPL stands for (READ, EVAL, PRINT, LOOP). Node js comes with bundled REPL environment. This allows for the easy creation of CLI (Command Line Interface) applications.
The Event loop handles all async callbacks. Node.js (or JavaScript) is a single-threaded, event-driven language. This means that we can attach listeners to events, and when a said event fires, the listener executes the callback we provided.

Whenever we are call setTimeout, http.get and fs.readFile, Node.js runs this operations and further continue to run other code without waiting for the output. When the operation is finished, it receives the output and runs our callback function.
So all the callback functions are queued in an loop, and will run one-by-one when the response has been received.
Asynchronous literally means not synchronous. We are making HTTP requests which are asynchronous, means we are not waiting for the server response. We continue with other block and respond to the server response when we received.

The term Non-Blocking is widely used with IO. For example non-blocking read/write calls return with whatever they can do and expect caller to execute the call again. Read will wait until it has some data and put calling thread to sleep.
Streams are objects that enable you to read data or write data continuously.
There are four types of streams:
Readable : Used for reading operations
Writable : Used for write operations
Duplex : Can be used for both reading and write operations
Transform : A type of duplex stream where the output is computed based on input