Node.js Overview

Table of Contents

Introduction to Node.js

Node.js is an open-source JavaScript server environment. It’s free and runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.). Operating efficiently within a single process, it handles I/O operations without blocking, enabling it to manage numerous connections without the complexity of thread concurrency. Moreover, it empowers frontend developers familiar with JavaScript to seamlessly code on the server side and adapt ECMAScript standards without waiting for browser updates.

Installation of Node.js

On Windows

  1. Download the Installer:
    Download official Node.js for Windows from here. Choose the right version for your local machine. Then a .msi file will be downloaded to your browser. Choose a location to save that file.
  2. Install Node.js and NPM:
    • Double-click the .msi binary files to initiate the installation process. You will see the following “welcome window”:
      WindowsDownloadWelcome
    • Click “Next” button. The installation process will start.
    • Choose the path where you want to install Node.js and then click “Next”, like the graph shown below:
      WindowsDownloadPath
    • If you want to install NPM simultaneously, choose npm package manager on the custom setup page and click “Next”, like below:
      WindowsDownloadNPM
    • And then click “Install”.
  3. Check Node.js and NPM Version:
    • Open “Command Prompt”
    • To confirm Node installation, type: node -v
    • To confirm NPM installation, type: npm -v

On Mac

  1. Download the Installer:
    Download official Node.js for Mac from here. Choose the right version for your local machine. Then a .pkg file will be downloaded to your browser. Choose a location to save that file.
  2. Run Node.js Installer:
    The installer will be opened automatically, follow these steps:
    Introduction > Continue License > Select Continue > Agree Installation Type > Install > Authenticate with your Mac to allow the Installation > Install Software Summary > Close.
    The installation will be done.
  3. Verify Node.js Installation:
    • Open “Terminal”
    • Type: node -v
  4. Install NPM using Homebrew:
    See details here.

Get Started with Node.js

Once downloaded and installed Node.js, try displaying “Hello World” in a web browser:

const http = require('node:http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Hello World\n');
});
server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Additional Resources

Reference