Specify a Specific Version of Node.js for Services
In ServBay, it is very simple to specify a specific version of the Node.js runtime environment for a project, a certain Node.js script, or a website. This article will detail how to specify a specific Node.js version for Node.js scripts and websites.
Specify a Specific Version of Node.js for Your Project
ServBay supports project-level Node.js environment settings, which are implemented through the .servbay.config
file. Through the .servbay.config
file, you can specify project-level configurations for the Node.js runtime version, repository address, cache directory, etc.
For detailed settings and usage methods, please refer to the article Using .servbay.config File.
Specify a Specific Version of Node.js for a Node.js Script
If you do not want to set the Node.js version at the project level and simply want to temporarily call a specific version of Node.js, you can use this method.
In ServBay, you can easily specify the Node.js version used by a Node.js script via the command line. Just use the node-<version>
command. For example, to run a script with Node.js 14, you can execute the following command:
$ node-14 script.js
Hello World
Node.js Version: 14.17.0
$ node-16 script.js
Hello World
Node.js Version: 16.3.0
2
3
4
5
6
7
Explanation of Examples
node-14 script.js
: Run thescript.js
script using Node.js version 14.node-16 script.js
: Run thescript.js
script using Node.js version 16.
With this approach, you can flexibly test and run different Node.js versions for compatibility.
Specify a Specific Version of Node.js for Your Website
TIP
This feature will be supported in the new version of ServBay.
If you need to specify the Node.js runtime version for the entire website, you can set it through the ServBay management interface.
Steps
Open the ServBay Management Interface: Find and open ServBay in the application.
Navigate to Website Settings: Click on
Website
in the navigation menu.Select the Specific Website: Find the specific website you need to set in the website list, and click the Node.js version dropdown menu on the right.
Select Node.js Version: In the settings dropdown menu, select the Node.js version you wish to use. Ensure that the respective Node.js version's service is installed and running.
Notes
- Ensure Node.js Version is Installed: Before selecting the Node.js version, please ensure that the required version of Node.js is installed and running in ServBay.
- Compatibility Check: After switching the Node.js version, it is recommended to check the compatibility of the website to ensure that all functionalities are operating normally.
Summary
In ServBay, specifying a specific version of the Node.js runtime environment is very simple. You can specify the project-level Node.js runtime version through the .servbay.config
file, directly specify the Node.js version for running Node.js scripts via the command line, or specify the Node.js version for the entire website through the ServBay management interface. Whether for a project, a single script, or an entire website, you can flexibly switch Node.js versions to meet different development and runtime needs.