What makes Node such a popular choice for many development projects?
One of nodes most compelling features is how it implements the concept on
non-blocking I/O. Node embraces non-blocking I/O to improve performance for a number of application types.
Key strengths of Node
- Efficiently distributes small pieces of information
- Easily scales to multiple processors or servers
- standard library, module system, and npm
As with many software programming frameworks, you don’t necessarily need to be an expert in the programming language, but knowing enough of the basics stands you in good stead to mastering the framework, and over time you will master the programming language
Document Object Model (DOM).
C++, Java, C# or Python.
Node.js is a server-side framework, one of it’s main works is to handle any number of requests. In traditional I/O bound servers systems, a request can only be issued when the response to the previous request has arrived. This is typically referred to as blocking I/O.
Node.JS is a non-blocking I/O, If a request takes long time, Node.js sends that request in an event loop and moves on to handle the next request in the call stack. As soon as the pending request is done processing, it raises an event and the response is rendered on the browser.
In commonly in event-driven architecture systems, servers perform tasks that might take a while to complete, like call an API or access a database.
I recommend installing Node.js on your workstation using Node Version Manager (NVM), which enables you to easily install multiple different versions of Node on your workstations.
There are two primary ways to use Node.js on your machines: using the
Node shell, is also called
Node REPL — REPL stands for Read-Eval-Print-Loop . Used quickly test things in Node. If you don’t
remember exactly how a function should be used, you can just quickly use the REPL and type in something to see what happens.
To launch the Node shell, you simply type node in a terminal window you are using:
> is all the response you get. You can immediately start typing in some code:
The first line of the output is the result of the code you just executed. You made use the Node global variable
console and its
log function to print out Hello World! The output of this statement is Hello World! , which is printed to terminal window.
undefined output is always the resulting value of the preceding statement. Every statement, function call, or expression has a value associated with it, which is printed out in the Node shell for you.
If there is no evaluated expression value or the called function does not return any particular value, the special value
undefined is returned instead.
To exit out of the REPL environment use Ctrl + D
To demonstrate this, create and save the following to a file called
Now, you can execute this file from the terminal window by ensuring you change into the directory i.e.
cd NodeSample or whatever you named your directory then simply using the node to execute the file
And you should see this output:
We are not using the Node shell, in this instance so you don’t get any information on the return values of the code executed.
We’ve briefly reviewed some key core node concepts and have installed node on your machine. We’ve also verified that node is working on your machine. You can now quickly run through the create a simple node.js module tutorial and build a simple web server.