Introduction
Before writing Node.js applications, you need a properly configured development environment. This involves installing Node.js itself (which bundles npm), choosing an appropriate version, and setting up a basic project structure. Node.js releases follow a predictable schedule: even-numbered major versions (e.g. 18, 20, 22) become Long-Term Support (LTS) releases, recommended for production use because they receive stability and security updates for an extended period.
Cricket analogy: Before stepping onto the pitch, a player needs the right kit fitted and checked, much like installing Node.js and npm before coding; and just as international teams trust players with several seasons of proven form (the even-numbered LTS releases), production apps trust the stable, long-supported Node versions.
How It Works
Node.js can be installed directly from nodejs.org, via an OS package manager, or — the recommended approach for developers — via a version manager like nvm (Node Version Manager). A version manager lets you install and switch between multiple Node.js versions on the same machine, which is essential when different projects require different versions.
Cricket analogy: Node.js can be installed straight from the official source like buying gear from the official kit supplier, through a general store like an OS package manager, or -- the pro's choice -- through a kit manager like nvm that lets a player switch between different bat weights (Node versions) for different match formats.
# Install nvm (Linux/macOS), then:
nvm install --lts
nvm use --lts
node --version
npm --versionExplanation
nvm install --lts downloads and installs the latest LTS release of Node.js, and nvm use --lts activates it for the current shell session. Once installed, node --version and npm --version confirm the active versions. A typical new project is initialized with npm init -y to generate package.json, followed by creating an entry file (commonly index.js or app.js) and a .gitignore that excludes node_modules and environment files.
Cricket analogy: nvm install --lts is like ordering the latest officially approved match kit, and nvm use --lts is like suiting up in it for today's game; checking node --version and npm --version is like confirming your kit tag before walking out, and npm init -y is like filling out the team registration sheet before adding your squad list (a .gitignore excluding node_modules and env files, so you don't hand opponents your private strategy notes).
Example
mkdir my-node-app && cd my-node-app
npm init -y
echo "node_modules/\n.env" > .gitignore
echo "console.log('App started');" > index.js
node index.jsOutput
Wrote to /path/my-node-app/package.json
App startedKey Takeaways
- Use a version manager like nvm to install and switch between Node.js versions per project.
- Prefer even-numbered LTS releases for production stability and long-term security updates.
- npm init -y quickly scaffolds a package.json for a new project.
- Always .gitignore node_modules and files containing secrets like .env.
- Verify your setup with
node --versionandnpm --versionbefore starting development.
Practice what you learned
1. What is the main advantage of using nvm to install Node.js?
2. Which Node.js releases are designated as Long-Term Support (LTS)?
3. What command quickly creates a default package.json without interactive prompts?
4. Why should node_modules typically be added to .gitignore?
Was this page helpful?
You May Also Like
npm and Package Management
Learn how npm manages dependencies, scripts, and versioning for Node.js projects via package.json.
Introduction to Node.js
Learn what Node.js is, why it exists, and how it lets JavaScript run outside the browser on servers.
Environment Variables and Configuration
Learn how to manage configuration and secrets in Node.js apps using environment variables and dotenv.
Related Reading
Related Study Notes in Web Development
Browse all study notesWebSockets Study Notes
Web Development · 30 topics
Web DevelopmentWebAssembly Study Notes
WebAssembly · 30 topics
Web DevelopmentgRPC Study Notes
Protocol Buffers · 30 topics
Web DevelopmentSpring Boot Study Notes
Java · 30 topics
Web DevelopmentFlask Study Notes
Python · 30 topics
Web DevelopmentDjango Study Notes
Python · 30 topics