Node.js is a platform built on Chrome's JavaScript runtime for easily building fast and scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.

What is Node.js?

In simple words Node.js is "Server-side Javascript"

Features

  • Asynchronous and Event Driven - means the server never waits for an API to return data. 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. (non-blocking I/O)
  • Very Fast - built on Google Chrome's V8 JavaScript Engine
  • Command line tool
  • Modular
  • Javascript for both client and server side - works well with single page applications (React, Angular or simply jQuery)
  • Has a very good package manager (npm)

Node.js - REPL Terminal

REPL stands for Read Eval Print Loop and it represents a computer environment like a window console or Unix/Linux shell where a command is entered and system responds with an output in interactive mode. You can perform the following tasks;

 

  • Read - Reads user's input, parse the input into JavaScript data-structure and stores in memory.
  • Eval - Takes and evaluates the data structure
  • Print - Prints the result
  • Loop - Loops the above command until user press ctrl-c twice.

 

REPL feature of Node is very useful in experimenting with Node.js codes and to debug JavaScript codes.

Node Package Manager - NPM

Node Package Manager (npm) provides following two main functionalities:

 

  • Online repositories for node.js packages/modules which are searchable on search.nodejs.org
  • Command line utility to install Node.js packages, do version management and dependency management of Node.js packages.

 

Mostly used NPM commands

  • npm install <Module Name>
  • npm install binarysearch -g
  • npm update binarysearch
  • npm uninstall binarysearch
  • npm init   

package.json

package.json is present in the root directory of any Node application/module and is used to define the properties of a package.

npm comes bundled with Node.js

Installation

A Node.js application consists of following three important parts 

 

  • Import required modules − We use require directive to load a Node.js module.
  • Create server − A server which will listen to client's request similar to Apache HTTP Server.
  • Read request and return response − server created in earlier step will read HTTP request made by client which can be a browser or console and return the response.

Node.js - First Application

nodejs-tutorial

By Mert Kahyaoğlu