What is Node?

Node.js, otherwise known as Node, is an open source run-time environment that allows you to execute JavaScript code outside of a browser. Node can be used similarly to, for example, a Python interpreter that runs Python code. It’s available cross-platform, meaning you can host the Node.js application in all major operating systems including Windows, Mac OS and Linux.

“Node is a single-threaded, single-process system which enforces shared-nothing design with OS process boundaries. It has rather good libraries for networking. I believe this to be a basis for designing very large distributed programs. The “nodes” need to be organized: given a communication protocol, told how to connect to each other. In the next couple months [Node’s development team] is working on libraries for Node that allow these networks.”

Before Node, JavaScript could only be run inside a browser and thus had no access to the file system – one of the reasons there is no print statement in JS. Node is built off the V8, the Chrome JavaScript engine, but made into an independent runtime environment. It allowed JS to read and write files and talk to the internet independently. This created the option to make web servers with Node.js and it is now a popular choice for building full-stack applications (i.e, software development including both front-end and back-end).

Why Node?

Write some stuff here.

Asynchronous & Non-blocking

Synchronous programming models and languages such as PHP require things to happen one at a time. This means each process/ line of code waits for a return from the line ahead of it before executing. Compared to that, an asynchronous language such as Node allows the handling of multiple requests simultaneously.

Example: a frequent task for web servers is to open a file on the server and return the content to the client. In environments such as PHP or Python, the entire thread (a sequence of instructions to execute) is blocked and a new one must be created for the operation. This executes a sequence of instructions looking somewhat like:

Meanwhile, Node.js is what is known as a single-threaded process; it uses only a single thread for handling requests and a main worker thread. When the request is made, Node.js sends that request to the requests thread and returns to the main worker thread. It may receive another request before completion of the previous one – in that case it simply sends the request to the same thread and returns to work. Once a response is given, Node returns it to the client. How Node handles the request: