Skip to content

Node.js Getting Started Guide

Node.js Overview

What is Node.js?

Node.js is a JavaScript runtime environment based on the Chrome V8 engine, used to build high-performance network applications. It adopts an event-driven, non-blocking I/O model, making it lightweight and efficient.

Main Features

  • 🚀 Cross-platform: Supports Windows, macOS, and Linux
  • High Performance: V8 engine + async I/O
  • 📦 npm Ecosystem: The world's largest open-source library ecosystem
  • 🔄 Full Stack Development: Unified JavaScript for frontend and backend

Application Scenarios

  • Web server development
  • RESTful API services
  • Real-time applications (e.g., chat rooms)
  • Command-line tools
  • Microservice architecture

Install Node.js

Windows/macOS

  1. Visit the official website: Download NodeJS
  2. Choose the LTS (Long Term Support) version to download
  3. Run the installer and follow the prompts to complete installation

Linux (Ubuntu/Debian)

bash
# Install using NodeSource
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt-get install -y nodejs

Verify Installation

After installation, you can check the Node.js version with the following commands

bash
node -v
npm -v

npm Package Management

Common commands

CommandDescription
npm initInitialize project
npm install <package>Install package
npm install -g <package>Install package globally
npm uninstall <package>Uninstall package
npm update <package>Update package
npm listList all packages
npm run <script>Run script in package.json

Install pnpm Globally

  1. Install pnpm
bash
npm install -g pnpm
  1. Set mirror source
bash
pnpm config set registry https://registry.npmmirror.com

NVM (Node Version Manager)

What is NVM?

NVM is a Node.js version management tool that allows you to install and switch between multiple Node.js versions on the same machine.

Core Features

  • ✅ Install multiple Node.js versions in parallel
  • 🔄 Quickly switch versions (global/project level)
  • 🧹 Cleanly uninstall unnecessary versions
  • 🌐 Supports Windows/macOS/Linux

Application Scenarios

  • Test compatibility with different Node.js versions
  • Maintain multiple projects using different Node versions
  • Safely upgrade/downgrade Node versions

Windows Installation


macOS/Linux Installation

bash
# Use the install script (recommended)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

# Or use Homebrew (macOS)
brew install nvm

NVM Basic Usage

bash
nvm ls-remote        # View all remote versions
nvm ls               # View locally installed versions
bash
nvm install 20       # Install latest v20.x
nvm install 16.14.0  # Install specific version
bash
nvm use 20           # Temporarily switch
nvm alias default 20 # Set default version
bash
nvm current          # View current version
nvm run 14 app.js    # Run script with specified version
nvm uninstall 12     # Uninstall specified version

Contributors

Changelog

Released under the MIT License