Manually Deploying Node.js (Windows)
Description
This section guides you through the deployment of Node.js on a Windows ECS.
Node.js is a JavaScript runtime environment based on the Google Chrome's V8 engine. It helps you build responsive, scalable network applications easily. Based on the event-driven and non-blocking I/O model, Node.js is lightweight and efficient. It is ideal for running data-intensive real-time applications on distributed devices.
For more information about Node.js, see https://nodejs.org.
Windows Server 2022 and the Node.js software package node-v24.13.0-x64.msi are used as examples.
Prerequisites
- An ECS has been created. For details, see Purchasing an ECS in Custom Config Mode.
- An EIP has been bound to the ECS. For details, see Assigning an EIP.
Procedure
- Remotely connect to the ECS. For details, see Login Overview (Windows).
- Visit the Node.js official website, click Download on the top menu bar, and download the required installation package. Figure 1 Downloading the installation package
- Double-click the downloaded installation package and install Node.js as instructed. Figure 2 Installing Node.js
- Open a Command Prompt or Windows PowerShell window.
Enter node -v and npm -v to view the version information. If the following information is displayed, the installation is successful.
Figure 3 Checking versions
- Create a test project folder named TestFolder and a TXT file named test.txt. Figure 4 Creating a test file
- Double-click the test.txt file and copy the following content to the file.
You can configure the project content (res.end) and port (const port) based on your service requirements. In this example, the port is 3000, and the output is Hello World.
const http = require('http'); const hostname = '0.0.0.0'; const port = 3000; const server = http.createServer((req, res) => { res.statusCode = 200; res.setHeader('Content-Type', 'text/plain'); res.end('Hello World\n'); }); server.listen(port, hostname, () => { console.log(`Server running at http://${hostname}:${port}/`); }); - Change the file name extension of test.txt to test.js. Figure 5 Changing the file name extension
- Open the Command Prompt or PowerShell window. Go to the TestFolder directory and run the npm init command to initialize the project. Figure 6 Initialization
- Enter the project name and other required information as prompted to generate the package.json file. If you do not want to set other parameters, press Enter to skip them. Figure 7 Project details
- Run the node test.js command to run the Node.js project locally. Figure 8 Running the project
- Add an inbound rule to the security group of the ECS to allow access to port 3000 configured in the project. To enhance security, you are advised to allow access only from specific IP address ranges instead of from all IPv4 addresses (0.0.0.0/0). For details, see Adding a Security Group Rule.
- On a local Windows server or any other Windows server that can access the Internet, open a browser and visit http://<ECS-EIP>:<project-port>. In this example, the project port is 3000. Figure 9 Access successful
If the project cannot be accessed, check whether the security group port of the ECS is allowed or whether the Windows firewall is disabled.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot