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.
Node.js works on a V8 environment, it is a virtual machine that utilizes JS as its scripting language and achieves high output via non-blocking I/O and single threaded event loop.
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.
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. It is an application architecture technique divided into two sections:
Node.js can be used for the following purposes.
The two types of API functions in Node.js are:
A generic piece of code which runs in between several asynchronous function calls is known as control flow function.
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.
No, you cannot access DOM in node.
The two arguments that async.queue takes are:
An event loop is an event-listener which functions inside the NodeJS environment and is always ready to listen, process, and output for an event. An event can be anything from a mouse click to a keypress or a timeout.
Event loop is used to process and handle external events, and to convert them into callback invocations. So, at I/O calls, node.js can switch from one request to another.
By following steps you can async Node.js:
Pros:
Cons:
Node.js solves this problem by putting the event based model at its core, using an event loop instead of threads.
The difference between Node.js and Ajax is that, Ajax (short for Asynchronous JS 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 JS, used for developing server software. Node.js does not execute in the browser but in the server.
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.
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 JS "callback" on the main JS thread.
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.
Express is the most common framework used in node.js. Express acts as middleware: it helps set up and configure routes to send and receive requests between the front-end and the database of an app.
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.