Node.js Series: 10 things you should know about node.js!

Node.js is an open-source, cross-platform JavaScript run-time environment that executes JavaScript code server-side.

Node.js was originally written by Ryan Dahl in 2009.

10 important points about nodejs.js are as follows:

1. Open source

Projects can be useful for programmers. You can learn by reading the source code and build something on top of the existing projects. Being Open Source enables that.

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

2. Server Side Framework

JavaScript was used mainly for client-side scripting.

Client Side Scripting means scripts written in JavaScript are embedded in a webpage’s HTML and run client-side by a JavaScript engine in the user’s web browser.

Node.js lets developers use JavaScript to write Command Line tools and for server-side scripting—running scripts server-side to produce dynamic web page content before the page is sent to the user’s web browser.

[–>Official Node.js Certification: Price, Syllabus and popular online courses]

3. Asynchronous and Event Driven

APIs of Node.js library are asynchronous in nature, that is, non-blocking I/O which actually means that Node.js based server never waits for an API to return data.

I/O refers to input/output. It can be anything ranging from reading/writing local files to making an HTTP request to an API.

I/O takes time and hence blocks other functions.

[->Asynchronous call to a REST API using Node.js and using the Promises. ]

Example of Non-Blocking Code:

var fs = require("fs");

fs.readFile('inputfile.txt', function (err, data) {
   if (err) return console.error(err);

console.log("I will print first");

By above example you can verify that, The server moves to the next API after calling it and a notification mechanism of Events of Node.js helps the server to get a response from the previous API call.

4. Single Threaded

Node.js uses a single threaded model with event looping.

Event mechanism helps the server to respond in a non-blocking way and makes the server highly scalable as opposed to traditional servers which create limited threads to handle requests.

[–>Developing Chat Bot using node.js on Windows 10 with Microsoft Bot Framework]

5. No Buffering

Node.js applications simply output the data in chunks intead of buffering. This feature makes them very fast and scalable. Streaming websites like Netflix and other prefer Node.js for some part of their development.

6. Node Package Manager(NPM)

npm is a package manager for the JavaScript programming language. It is the default package manager for the JavaScript runtime environment Node.js.

Node Package Manager is the root of almost all deployment systems for Node.js and underlies the many PaaS (platform-as-a-service) providers for Node.js.

7. Callbacks

Node makes heavy use of callbacks. All the APIs of Node are written in such a way that they support callbacks.

[–>JavaScript: Converting a Callback to Promises]

8. Event Driven

Node.js uses events heavily and it is also one of the reasons why Node.js is pretty fast.

In an event-driven application, there is generally a main loop that listens for events, and then triggers a callback function when one of those events is detected.he functions that listen to events act as Observers.

// Import events module
var events = require('events');

// Create an eventEmitter object
var eventEmitter = new events.EventEmitter();

Following is the syntax to bind an event handler with an event −

// Bind event and event  handler as follows
eventEmitter.on('eventName', eventHandler);

We can fire an event programmatically as follows −

// Fire an event 

9. Express Framework

Express.js, is a web application framework for Node.js.

Key features of Express framework −

  • Has middlewares to respond to HTTP Requests.
  • Creates a routing table which is used to perform different actions based on HTTP Method and URL.
  • Dynamically rendering of HTML Pages based on passing arguments to templates
    (like handlebars).

[–>Building a REST API in NodeJS, Express and MongoDB]

10. Utility Modules

  • OS ModuleProvides basic operating-system related utility functions.
  • Net ModuleProvides both servers and clients as streams. Acts as a network wrapper.
  • Domain ModuleProvides ways to handle multiple different I/O operations as a single group.
  • Path ModuleProvides utilities for handling and transforming file paths.
  • DNS ModuleProvides functions to do actual DNS lookup as well as to use underlying operating system name resolution functionalities.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s