In the previous article, we have discussed how to deploy a local Java application directly to an Alibaba Cloud Elastic Compute Service (ECS) instance, and received a lot of feedback from our readers. So to help answer the questions from our readers, we will further introduce how to deploy a Node.js application to an Alibaba Cloud ECS instance in this article.
This article takes a Node.js application for printing "Hello World" on a Web page as an example to explain the deployment method.
const http = require('http');
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Alibaba Cloud Toolkit: Hello World');
});
server.listen(port, '0.0.0.0', () => {});
The preceding code is a standard Node.js project used to print the string "Hello World" on a Web page.
Alibaba Cloud provides an Eclipse-based plug-in to help developers efficiently deploy applications written in the local IDE to ECS instances.
URL of the plug-in: https://www.aliyun.com/product/cloudtoolkit_en
The installation process of this Eclipse-based plug-in is similar to that of a common plug-in, and therefore will not be detailed here.
After installing the plug-in, configure the preferences by choosing:
Top menu > Window > Preferences > Alibaba Cloud Toolkit > Accounts
When the following page is displayed, configure the AK and SK of your Alibaba Cloud account to complete the configuration of preferences.( If you are using a RAM user account, enter the AK and SK of the RAM user.)
In Eclipse, right-click the project name and choose Alibaba Cloud > Deploy to ECS from the shortcut menu. The following deployment window is displayed:
In the Deployment Configurations dialog box, set the deployment parameters, and click Deploy to complete the initial deployment.
The /root/nodejs-demo/restart.sh file contains the following content:
source ~/.bash_profile
killall node
nohup node /root/nodejs-demo/helloworld.js > nohup.log 2>&1 &
Deploying an Application to Container Service for Kubernetes
Deploying Applications to EDAS with Cloud Toolkit Maven Plug-in
Alibaba Clouder - March 29, 2019
Alibaba Clouder - August 13, 2020
Alibaba Clouder - November 14, 2017
Alibaba Cloud Indonesia - August 22, 2022
ApsaraDB - October 14, 2021
Alibaba Clouder - April 10, 2019
Robotic Process Automation (RPA) allows you to automate repetitive tasks and integrate business rules and decisions into processes.
Learn MoreA PaaS platform for a variety of application deployment options and microservices solutions to help you monitor, diagnose, operate and maintain your applications
Learn MoreGain an industrial edge with Alibaba Cloud best practices
Learn MoreAlibaba Cloud (in partnership with Whale Cloud) helps telcos build an all-in-one telecommunication and digital lifestyle platform based on DingTalk.
Learn MoreMore Posts by Nick(倪超)