Install Node.js dev environment

Setting up dev environment

Page content

Step-by step instructions on howto install nodejs with supporting tools.

Node.js logo

When

After getting nice new shiny laptop or reinstalling linux the next step for node.js developer is to install his/(other favorite prononces) favorite tools. Here I will list a sequence I’m doing this in.

Where

I’m using ubuntu linux mint flavour so all settles mostly on debian/ubuntu repositories and packages.

How

Install Node.JS with package manager

sudo apt-get update
sudo apt-get upgrade

sudo apt-get install nodejs npm

currently installs npm v 9.2.0

Install Node.JS Runtime from node site

Go to https://nodejs.org and download node.js for your OS.

For linux the currently available LTS version is v20.16.0.

You will need to

  • download it
  • untgz it to your favorite apps folder
  • add the bin subfolder to the path

My favorite is the next way:

Install NVM together with Node.JS

Node Version Manager (NVM) check on the github page

# installs nvm (Node Version Manager)
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# or
# curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash

# reopen terminal and
# check nvm is correctly installed
nvm --version

# download and install Node.js (you may need to restart the terminal)
nvm install 20

# verifies the right Node.js version is in the environment
node -v   # should print `v20.17.0` or later v20 version

# verifies the right npm version is in the environment
npm -v    # should print `10.8.2` or later version

To show list of node versions installed use the command

nvm ls

It will respond with available and version list with an active version on top nvm ls response

to switch to different version:

nvm use 18
nvm use 20

Install VS Code

Particularly we need some specific extensions:

  • ESLint
  • Prettier (Prettier - Code formatter)
  • Node.js Modules IntelliSense

you can search these extensions in the vs code extension tab manually or run in Launch VS Code Quick Open (Ctrl+P):

ext install ESLint
ext install Prettier - Code formatter
ext install Node.js Modules IntelliSense

Install Git and Docker

See for the details about these in: Reinstalling linux article.

you can check if they are installed correctly with

git --version
docker --version

Creating simple Node.js application

Create a local folder

cd ~
mkdir test-njs
cd njs

Run npm init and follow the prompts

npm init

It will look similar to this output:

npm init response

Now you can create a file app.js and here you go! Add a bit of code to create a simple api:


const http = require ('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 Node\n');
});

server.listen(port, hostname, () => {
    console.log(`Server running at http://${hostname}:${port}`)

});

now switch to vscode terminal (Ctrl+~) and type

node app.js

you will see the

Server running at http://127.0.0.1:3000

Navigate to this url (Ctrl+LClick on it) and you will see your default browser window with

Hello Node

Nice!