Lesson

Node.js Get Started

10 min reading
Free Course

Node.js Get Started: Installing Node.js and Running Your First Script

Getting started with Node.js takes two steps: installing a Long-Term Support (LTS) Node.js runtime and creating a package.json project manifest. Within minutes, you can execute .js files straight from your terminal without a browser.

Installing Node.js LTS and Verifying Versions

Always install the LTS (even-numbered) release—such as Node.js 20 LTS or 22 LTS—for stability in local and production projects. Using a version manager like nvm (macOS/Linux) or fnm / nvm-windows lets you switch Node versions per project without permission errors.

node -v
npm -v

Running node -v and npm -v confirms both the Node runtime and the bundled npm package manager are ready in your shell PATH.

Creating Your First Node.js Project

Create an empty project folder, generate a default package.json, and configure "type": "module" if you want modern import / export syntax across .js files.

mkdir hello-node
cd hello-node
npm init -y

Next, save a small script in app.js and run it with node app.js (or node --watch app.js in Node 18.11+ to restart automatically whenever you edit the file).

import os from 'node:os';

const user = process.env.USER || process.env.USERNAME || 'developer';
const memoryMb = Math.round(os.totalmem() / 1024 / 1024);

console.log(`Hello, ${user}!`);
console.log(`Running Node ${process.version} with ${memoryMb} MB RAM.`);

Common Mistakes to Avoid

  • Installing odd-numbered "Current" releases in production: Odd versions (like v21 or v23) have short support windows. Stick to even LTS releases for deployed services.
  • Using sudo npm install -g on macOS/Linux: Installing global packages as root causes file permission headaches later. Use nvm or fnm in your home directory instead.
  • Mixing require() and import inside one .js file: Pick either ES modules ("type": "module") or CommonJS consistently across your project.

Frequently Asked Questions

What does npm init -y do?

It creates a starter package.json file with default values immediately, skipping interactive prompts so you can start coding right away.

How do I run a script continuously during development?

Run node --watch app.js so Node.js restarts your script automatically whenever saved source files change—no external watcher package required.

How do I exit a Node.js interactive REPL session?

Press Ctrl + C twice, or type .exit and press Enter.

Save Your Progress

Unlock Your
Full Potential.

Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.

Quick Access With

Enterprise-Grade Security Protocol

Try it Yourself

Experiment with the code from this lesson in our interactive playground.

Open Playground
Node.js Topic Hub

Stuck on this lesson?

Join our community of senior developers.

Ask in Forum