Installing Node.js & Running Your First Script
7 min read
Installing Node.js
The recommended way to install Node.js is via nvm (Node Version Manager), which lets you switch between multiple Node versions easily. Alternatively, you can download an installer directly from nodejs.org.
bash
# Install nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
# Install the latest LTS version of Node.js
nvm install --lts
nvm use --lts
# Verify installation
node --version
npm --versionRunning Your First Script
Once Node.js is installed, create a .js file and run it with the node command. The global console object works exactly as it does in the browser.
js
// hello.js
const greeting = "Hello from Node.js!";
console.log(greeting);
console.log("Node version:", process.version);bash
node hello.js
# Hello from Node.js!
# Node version: v20.11.0Always use an LTS (Long-Term Support) version in production. LTS releases receive security patches for 30 months.
Ready to test yourself?
Practice Node.js— quiz & coding exercises