Node.js - Overview

Updated: 2020-09-27

What is Node.js

Node.js is a Javascript runtime, which means it can parse and execute javascript code:

$ node
> var a = 1;
> a + 1

It is built on V8, the Javascript engine for Chrome, it shares the same features that run in the browser. And Node adds a few APIs beyond V8.

Node doesn’t run any of your application code in parallel

Why Node.js

  • same language(Javascript) for both server and client side.
  • event-driven, non-blocking I/O
  • npm, the package manager
  • awesome (and growing) libraries:

Install Node.js

Install node.js on Ubuntu

$ curl -sL | sudo bash -
$ sudo apt-get install -y nodejs

Install npm

$ sudo apt-get install npm

Upgrade Node

Upgrade node and npm:

$ npm install -g node
$ npm install -g npm

Or use n:

sudo npm cache clean -f
sudo npm install -g n

# install stable version
sudo n stable

# install latest version
sudo n latest

sudo ln -sf /usr/local/n/versions/node/<VERSION>/bin/node /usr/bin/node

Check Versions And Upgrade

Check version of node:

$ node -v

Check version of npm:

$ npm -v