Guide to Independently Configure Node.js Versions for Projects Using ServBay
ServBay, as an integrated development environment, natively supports the parallel management and quick switching of multiple Node.js versions, solving the complexity and resource consumption issues of traditional tools (like NVM or Docker). Below is a complete configuration solution for common scenarios:
Project-Level Version Control via .servbay.config
1. Core Principles
ServBay pre-installs all mainstream versions of Node.js v12 to v23 on macOS (arm64/x86_64). Each project can dynamically bind to the required version through a configuration file.
Advantages:
• No need for manual installation or compilation, avoiding version conflicts
• Supports running multiple versions simultaneously (e.g., project A with Node 18, project B with Node 22)
• Decoupled from services like PHP and databases, allowing independent runtime environments without polluting the system
2. Configuration Steps
Step 1: Create Configuration File
In the root directory of the project, create a .servbay.config
file and add the following content:
NODE_VERSION=20 # Specify Node.js 20.x
# Optional: Configure npm/pnpm mirror (for network acceleration)
YARN_CONFIG_REGISTRY=https://npmreg.proxy.ustclug.org/
NPM_CONFIG_REGISTRY=https://registry.npmmirror.com
NPM_CONFIG_CACHE=/Applications/ServBay/tmp/npm/cache
2
3
4
5
Step 2: Verify Version Effectiveness
$ node -v
v20.12.2 # Should match the configuration file
$ npm run dev # Dependency resolution is based on the current Node version
2
3
3. Advanced Features
• Multiple Version Coexistence: Automatically loads the corresponding version of Node.js when switching directories in the same terminal window
• Cache Management: Specify the cache directory using NPM_CONFIG_CACHE
to avoid global pollution
• Toolchain Support: Built-in package managers like npm, pnpm, and yarn, with versions strictly matching Node.js
Running Example
The following practical example demonstrates the operation mechanism of .servbay.config
.