- Documentation
Elastic Compute Service
Elastic Compute Service
Best Practices
Self-service website creation
Building environments
Setting up a Node.js environment
Building environments
Setting up a Node.js environment
Setting up a Node.js environment
Node.js is a JavaScript runtime environment built on the Chrome V8 engine. It leverages an event-driven, non-blocking I/O model, enabling the seamless development of responsive and scalable network applications. This topic describes how to deploy this environment on a Linux instance.
Software versions
- Operating system: In the example provided in this topic, CentOS 8.3 is used.
- Node.js: In the example provided in this topic, v6.9.5 and v10.14.2 are used.
Prerequisites
- An EIP is associated with the Linux instance, enabling the instance to connect to the Internet. For information about how to associate an EIP with an ECS instance, see Associating EIPs.
Step 1: Install Node.js
- You can select one of the following installation methods based on your business requirements.
- Use NVM to install multiple versions
- Execute the following command to install Git.
- Execute the following commands to clone the source code into your local ~/.nvm directory by using Git, and check for the latest version.
- Execute the following command to activate NVM and write it to the profile file.
- Execute the following command to make the environment variables take effect.
- Execute the following command to view all versions of Node.js.
- Execute the following commands to install multiple required Node.js versions.
- Execute the following command to view the installed Node.js versions.
- If the following output is displayed, the installation is successful and the current version in use is v10.14.2.
-
- Execute the following command to switch versions.
- If the following output is displayed, the switch is successful.
-
- Use platform binary files to install Node.js
- Execute the following command to download the Node.js installation package.
- Execute the following command to view the Node.js and npm versions.
- Use binary files from the Node.js official website to install Node.js
- Execute the following command to download the Node.js installation package. You can visit the official Node.js website to download more installation packages.
- Execute the following command to extract the installation package.
- Execute the following commands to create symbolic links for node and npm. After you create symbolic links, you can use the node and npm commands in any directory within the instance.
- Execute the following command to view the Node.js and npm versions.
Step 2: Deploy a sample project
- Execute the following command to enter the home directory of the instance.
- Execute the following command to create and open the project file test.js.
- Press the i key to enter edit mode, and then paste the following content into the file.
- const port: You can specify a port number based on your business requirements.
- Press the Esc key to exit edit mode, enter :wq, and then press Enter to save and exit the file.
- Execute the following command to run the project.
Step 3: Allow and test service ports
- In the inbound rules of the instance security group, allow "const port" and the IP address of the host intending to access the project.
- Click the instance name. On the "Overview" tab, click "Security Group". The "Security Group" tab is displayed.
- Click the "Edit rule" button. On the "Access rules > Inbound rules" tab, add a rule. Set "Strategy" to "Allow", select "TCP" for "Protocol type", set "Port range" to "const port", and set "Source" to the IP address of the host intending to access the project, as shown in the following figure. For more information, see Security group overview.
- In the local browser, enter http://<ECS instance EIP>:port number to access the test.js project.
Last updated: 2026.06.18 17:48:25