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 โ
- Visit the official website: Download NodeJS
- Choose the LTS (Long Term Support) version to download
- 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 nodejsVerify Installation โ
After installation, you can check the Node.js version with the following commands
bash
node -v
npm -vnpm Package Management โ
Common commands
| Command | Description |
|---|---|
npm init | Initialize project |
npm install <package> | Install package |
npm install -g <package> | Install package globally |
npm uninstall <package> | Uninstall package |
npm update <package> | Update package |
npm list | List all packages |
npm run <script> | Run script in package.json |
Install pnpm Globally โ
- Install pnpm
bash
npm install -g pnpm- Set mirror source
bash
pnpm config set registry https://registry.npmmirror.comVersion Management (Recommended) โ
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 nvmNVM Basic Usage โ
bash
nvm ls-remote # View all remote versions
nvm ls # View locally installed versionsbash
nvm install 20 # Install latest v20.x
nvm install 16.14.0 # Install specific versionbash
nvm use 20 # Temporarily switch
nvm alias default 20 # Set default versionbash
nvm current # View current version
nvm run 14 app.js # Run script with specified version
nvm uninstall 12 # Uninstall specified version
nuyoah