Introduction To Node.js

Jayamini samaratunga
3 min readMar 21, 2021

Node.js is a cross-platform runtime environment built on Google chrome’s V8 Javascript engine.

It has been developed by Ryan Dahl to create real-time websites with push capabilities (WebSockets).

Node.js applications are written in JavaScript and They can run within the Node.js runtime on OS X, Microsoft Windows, and Linux.

Node.js contains a library of several JavaScript modules that simplifies the development of web applications using Node.js.

Features of Node.js

Asynchronous & Event-Driven: All APIs of Node.js library are asynchronous which makes them non-blocking. Thus Node.js based server never waits for an API to return data. A notification mechanism helps the server to get a response from the previous API call as it moves to the next API after calling it.

No Buffering: Node.js applications never buffer any data as they simply output the data in chunks.

License: Node.js is released under the MIT license.

Single-Threaded but Highly Scalable: Node.js uses a single-threaded model with event looping. The event mechanism helps the server to respond in a non-blocking way which makes the server highly scalable compared to the traditional model which creates a minimal number of threads to operate requests. Node.js uses a single-threaded program that can provide service to a large number of requests than traditional servers.

Very Fast: As it is built on Google Chrome’s V8 JavaScript engine Node.js library is fast in code execution.

Event Loop

This allows Node.js to perform non-blocking I/O operations even though JavaScript is Single-threaded. It is done by allocating operations to the OS whenever and wherever possible. Multiple operations running in the background can be handled as most of the operating systems are multi-threaded. when one of these assigned operations is done, the kernel informs Node.js, and the respective callback assigned to that operation is added to the event queue which will then be executed.

Download Node.js

You can refer to the instructions given in https://nodejs.org ; and successfully download Node.js.

Getting Started

After you have successfully downloaded and installed Node.js on your computer, let’s try to display “Hello World” in a web browser.

First create a Node.js file named “helloWord.js”, and code as following.

Save the file as: C:\Users\yourName\helloWorld.js

Command Line Interface

Node.js files must be initiated in the Command Line Interface of your pc. To open Command Line Interface in windows search for “Command prompt” and set the path to the folder you saved the helloWorld.js file or you can simply type cmd on the address bar of the folder you saved the helloWorld.js file.

Initiate the Node.js File

.js file you created must be initiated by Node,js before any other action so let’s initiate it by, writing node helloWorld.js and press enter.

Now, your computer works as a server!

If anyone tries to access your computer on port 8080, they'll get a “Hello World! ” message!

Open your internet browser and type http://localhost:8080 to view the “Hello World! ” message.

You can refer to this video on how to get started with Node.js for more information!

please clap 👏 if you found this article useful

See you soon with another article! 🤞

--

--