---
title: "Introduction of Node.js"  
description: "In this article, I am explaining the concept of nodejs."  
author: "Anchal Kesharwani"  
published: 2014-08-18  
updated: 2017-11-29  
canonical: https://www.mindstick.com/articles/1453/introduction-of-node-js  
category: "node.js"  
tags: ["node js"]  
reading_time: 3 minutes  

---

# Introduction of Node.js

In this article, I am explaining the concept of nodejs.\

##### Introduction

“Node.js is a packaged compilation of Google’s V8 JavaScript engine, the libuv platform abstraction layer, and a core library, which is itself primarily written in JavaScript.” Beyond that, it’s worth noting that Ryan Dahl, the creator of Node.js, was aiming to create real-time websites with push capability, “inspired by applications like Gmail.

To start using Node.js, you must first understand the differences between Node.js and traditional server-[side scripting](https://www.mindstick.com/forum/156500/is-javascript-only-client-side-scripting-language) environments (eg: PHP, Python, Ruby, etc). Node.js uses a module architecture to simplify the creation of complex applications.

Chances are good that you are familiar with [asynchronous programming](https://www.mindstick.com/articles/338169/exploring-the-power-of-asynchronous-programming-in-c-sharp); it is, after all, the "A" in Ajax. Every function in Node.js is asynchronous. Therefore, everything that would normally block the thread is instead executed in the background. This is the most important thing to remember about Node.js. For example, if you are reading a file on the [file system](https://www.mindstick.com/forum/157850/what-is-a-file-system-explain-it-s-used-in-system-software), you have to specify a [callback function](https://www.mindstick.com/forum/157808/what-is-a-callback-function-and-how-is-it-used-in-javascript) that is executed when the read operation has completed.

Node.js is only an environment - meaning that you have to do everything yourself. There is not a default [HTTP server](https://www.mindstick.com/forum/160008/how-to-create-a-simple-http-server-using-node-js), or any server for that matter. This can be overwhelming for new users, but the payoff is a high performing web app. One script handles all communication with the clients. This considerably reduces the number of resources used by the application. For example, a node.js code for simple loop which iterate number of times and it consumes less time to other [server side](https://www.mindstick.com/forum/143/close-popup-window-by-server-side-code) language as like PHP.

Modules

Node.js uses a module architecture to simplify the creation of complex applications. Modules are akin to libraries in C, or units in Pascal. Each module contains a set of functions related to the "subject" of the module. For example, the http module contains functions specific to HTTP. Node.js provides a few core modules out of the box to help you access files on the file system, create HTTP and TCP/UDP servers, and perform other useful functions.

Module are include by simply calling the require() function, like this:

var http = require('http');

The require() function returns the reference to the specified module. In the case of this code, a reference to the http [module is stored](https://www.mindstick.com/interview/2652/how-module-is-stored-in-erlang) in the http variable.

In the above code, we passed the name of a module to the require() function. This causes Node to search for a node_modules folder in our application's directory, and search for the http module in that folder. If Node does not find the node_modules folder (or the http module within it), it then looks through the global module cache. You can also specify an actual file by passing a relative or absolute path, like so:

var myModule = require('./mySampleModule.js');

The modules are encapsulated with pieces of code. The code means it have functions and variables.

Global Scope

Node is a JavaScript environment running in Google's V8 JavaScript engine. As such, we should follow the [best practices](https://www.mindstick.com/articles/337564/building-a-microservices-architecture-with-laravel-best-practices) that we use for client-side development. For example, we should avoid putting anything into the global scope. That, however, is not always possible. The global scope in Node is GLOBAL (as opposed to window in the browser), and you can easily create a [global variable](https://answers.mindstick.com/qa/104739/define-global-variable) of function by omitting the var keyword, like this:

globalVariable = 1;

globalFunction = function () { ... };

Once again, globals should be avoided whenever possible. So be careful and remember to use var when declaring a variable.

Conclusion

In this blog, we [describe the concept](https://www.mindstick.com/forum/158622/describe-the-concept-of-a-divide-by-zero-exception-and-how-to-handle-it) of node.js and modules, and scope.

---

Original Source: https://www.mindstick.com/articles/1453/introduction-of-node-js

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
