All Guides

Node.js and npm Setup

Install Node.js runtime and npm package manager.

Beginner10 min

Setup Steps

1. Add the NodeSource repository (Node.js 20 LTS):

curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -

2. Install Node.js:

sudo apt install nodejs -y

3. Check versions:

node --version
npm --version

4. Alternative: Install with nvm (recommended):

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install 20
nvm use 20
nvm alias default 20

5. Install global packages:

npm install -g yarn pnpm

6. Start a new project:

mkdir project && cd project
npm init -y

7. Install packages:

npm install express
npm install -D typescript @types/node

8. package.json scripts:

"scripts": {
  "dev": "node --watch index.js",
  "start": "node index.js"
}