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.
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.
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.`);
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.require() and import inside one .js file: Pick either ES modules ("type": "module") or CommonJS consistently across your project.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.
Run node --watch app.js so Node.js restarts your script automatically whenever saved source files change—no external watcher package required.
Press Ctrl + C twice, or type .exit and press Enter.
Sign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.