Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page
Help Center/ Elastic Cloud Server/ Best Practices/ Setting Up an Environment/ Manually Deploying Node.js (CentOS 7.2)

Manually Deploying Node.js (CentOS 7.2)

Updated on 2024-11-04 GMT+08:00

Overview

The best practices for Huawei Cloud ECS guide you through the manual deployment of Node.js on a Linux ECS.

Node.js is a JavaScript runtime environment based on the Google Chrome V8 engine for building fast and scalable network applications. 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.

This section uses CentOS 7.2 64bit (40 GB) and Node.js installation packages node-v10.14.1-linux-x64.tar and node-v10.14.2-linux-x64.tar as an example to describe how to deploy Node.js.

Prerequisites

Procedure

  1. Install the Node.js software packages.

    • Using the binary file
      1. Log in to the ECS.
      2. Run the following command to download the Node.js installation package:

        wget https://nodejs.org/dist/v10.14.1/node-v10.14.1-linux-x64.tar.xz

      3. Run the following command to decompress the file:

        tar xvJf node-v10.14.1-linux-x64.tar.xz

      4. Run the following commands in any directory to set up a soft connection for node and NPM, respectively:

        ln -s /root/node-v10.14.1-linux-x64/bin/node /usr/local/bin/node

        ln -s /root/node-v10.14.1-linux-x64/bin/npm /usr/local/bin/npm

      5. Run the following commands to check the node and NPM versions:

        node -v

        npm -v

    • Using the NVM version manager
      1. Log in to the ECS.
      2. Run the following command to install git:

        yum install git

      3. Run the following command to copy the source code to the local ~/.nvm directory using git and check the version:

        git clone https://github.com/cnpm/nvm.git ~/.nvm && cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`

      4. Run the following command to activate NVM and add it to the profile file:

        echo ". ~/.nvm/nvm.sh" >> /etc/profile

      5. Run the following command for the environment variables to take effect:

        source /etc/profile

      6. Run the following command to list available Node.js versions:

        nvm ls-remote

      7. Run the following command to install multiple Node.js versions:

        nvm install v10.14.1

        nvm install v10.14.2

      8. Run the following command to check the installed versions:

        nvm ls

      9. Run the following command to switch the Node.js version to V10.14.2:

        nvm use v10.14.2

        NOTE:
        • Run the nvm alias default v10.14.2 command to set the default version to 10.14.2.
        • Run the nvm help command to obtain more information about NVM.

  2. Verify the deployment.

    1. Run the following command to go to the home directory:

      cd

    2. Run the following command to create a test.js project file:

      touch test.js

    3. Use VIM to edit the test.js file.
      1. Run the following command to open the test.js file:

        vim test.js

      2. Press i to enter insert mode.
        Modify the file as follows:
        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}/`);
        });
        The port number can be customized.
      3. Press Esc to exit insert mode. Then, enter :wq to save the settings and exit.
    4. Run the following command to view enabled port:

      netstat -lntp

      If the port is unavailable, log in to the ECS console and change the security group rule. For details, see Adding a Security Group Rule.

    5. Add exception ports in the firewall configuration.
      1. For example, to add port 3000, run the following command:

        firewall-cmd --zone=public --add-port=3000/tcp --permanent

        If the following information is displayed, the firewall is disabled. Then, go to step 2.f.
        [root@ecs-centos7 ~]# firewall-cmd --zone=public --add-port=3000/tcp --permanent
        FirewallD is not running
        If the following information is displayed, the firewall is enabled, and the exception port has been added:
        [root@ecs-centos7 ~]# firewall-cmd --zone=public --add-port=3000/tcp --permanent
        success
      2. Reload the policy configuration for the new configuration to take effect.

        firewall-cmd --reload

      3. Run the following command to view all enabled ports:

        firewall-cmd --list-ports

        [root@ecs-centos7 ~]# firewall-cmd --list-ports
        3000/tcp
    6. Run the following command to run the project:

      node ~/test.js

    7. Enter http://EIP:3000 in the address bar to access Node.js. If the following page is displayed, Node.js has been deployed.
      Figure 1 Deployment and testing

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback