Start an http/https server
Make http/https requests to other web servers
Start the TCP/UDP server or to make TCP/UDP requests
Read and write content on the filesystem
Spawn and manage new processes on operating system
The feature that separates node.js from other platforms is what is known as evented I/O. In node.js, during an I/O operation, whenever a chunk of data is read or written, an event is emitted. The programmer needs to register callbacks to react to these events, for example, to aggregate the chunks being read, or to determine whether the operation has been completed. This allows for making the I/O operations asynchronous, thus saving CPU cycles from being wasted. Other platforms make use of CPU time during I/O operations through multithreading. But an event-driven approach is much more efficient, because there is no thread spawning overhead and the memory footprint is much smaller.
To assist the evented I/O model, node.js has an event loop, which is constantly asking if there are there any more events to process. Whenever an event occurs, it gets registered into an event queue. The event loop executes the event handlers in the queue one by one. If there are no more events to process, the node.js runtime exits; of course, that is not true if you have started a server, in that case it will wait for events to occur.
To translate I/O operation into events, node.js uses
libuv is a C++ library that provides infrastructure for evented I/O. The actual magic happens in the libraries written on top of
Every mature platform has to face problems of modularization and redistribution of code. This is exactly the problem that Maven solved for Java, or the problem that Gems solved for Ruby, and thus npm for node.js.
npm allows us to register our packages with a name so that we can import/export these packages using the registered name. Moreover, npm also integrates with the npm registry. The npm registry is a web service that hosts such packages. The standard npm registry is hosted at https://npmjs.org. It is accessible on open internet and is maintained by Joyent, the organization that sponsors node.js development. We can publish our packages on the npm registry, and it can be found on the npm registry website by its name. For example, an author has published his package by the name "express". We can obtain that package by running
npm install express on our machine or by visiting http://npmjs.org/package/express. This way of distributing code over the internet is the reason why npm exists.
Previously, npm required separate installation. Recent versions of node.js ships with npm included.
Now that we know what node.js and npm are, in the next section we shall proceed to installing node.js on a computer.