Show List

Introduction to Node.js

Node.js is open source JavaScript run time environment that executes JavaScript code outside a web browser. Node.js is single threaded and has asynchronous event driven non blocking architecture. Node.js runs on chrome v8 engine which converts JavaScript code into machine code.

At the back end Node.js uses worker pool threads that work synchronously and are managed using C library libuv. 

Here are some of the features of Node.js
  • Asynchronous
  • Used Event Driven Architecture
  • Single Threaded
  • Highly Scalable
  • Very Fast
  • No Buffering
  • Fast Data Streaming
  • Can be used for both front end and back end development

Where to use Node.js

Node.js is used for I/O intensive operations and should not used for CPU intensive operations. Here are some of the areas where Node.js is used:
  • High I/O applications
  • Data Streaming Applications
  • Single Page Applications
  • API based applications

Node.js Modules and Packages

Module in Node.js is a single JavaScript file that performs a particular task and holds some functionalities. Module can be loaded by using the Node.js require() function. 
There are three types of Node.js modules:

  • Core Modules: Built-in modules that come with Node.js installation. Examples: http, fs, os, url.
  • Local Modules: Created locally in the application to provide specific functionality.
  • Third Party Modules: These are available online and are installed using the node package manager (NPM). Examples: express, mongoose, angular. 
To load the module requested in the require() function, node js first looks up in the native module, then goes to the parent folders to find package.json and node modules folder and looks up for that module.

A package is a directory with one or more modules inside of it and a package.json file which has metadata about the package.

Difference between running the JavaScript on browser and Node.js

  • Unlike browser Node.js has access to file system, network, other applications on the system.
  • Browser APIs related to DOM and CSS, Performance, Document, window are not available in Node.js.
  • In a browser, global scope is the window object. In Node.js, global object represents the global scope. To add something in global scope, you need to export it using export or module.export.  

    Leave a Comment


  • captcha text