This article will show you how to use the Cloud Toolkit to deploy a ** Node.js ** application on a ** Alibaba Cloud ECS instance **.
In the previous article, I explained how to deploy a local Java application directly to an instance of Alibaba Cloud Elastic Compute Service (ECS), and many readers read it. I received feedback. So, to answer your readers' questions, this article will also show you how to deploy a Node.js application on your Alibaba Cloud ECS instance.
In this article, I will explain how to deploy using a Node.js application that prints "Hello World" on a web page as an example.
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 code above is a standard Node.js project for displaying the string "Hello World" on a web page.
Alibaba Cloud provides Eclipse-based plugins that allow developers to efficiently deploy applications written in their local IDE to ECS instances.
Plugin URL: https://www.aliyun.com/product/cloudtoolkit_en
The procedure for installing this Eclipse-based plug-in is similar to a typical plug-in, so we won't go into details here.
After installing the plugin, select it and configure the preferences.
Top Menu> Window> Preferences> Alibaba Cloud Toolkit> Account
When the following page is displayed, set the AK and SK of the Alibaba Cloud account, and the setting of the environment setting is completed (If you are using a RAM user account, enter the AK and SK of the RAM user ).
Right-click on the project name in Eclipse and select Alibaba Cloud> Deploy to ECS from the shortcut menu. The following deployment screen will be displayed.
In the Deployment Settings dialog box, set the deployment parameters and click Deploy to complete the initial deployment.
The /root/nodejs-demo/restart.sh file contains the following:
source ~/.bash_profile
killall node
nohup node /root/nodejs-demo/helloworld.js > nohup.log 2>&1 &
--Deploy File: There are two options. The optional Upload File is used in your Node.js project. --Maven Build: If you are using Maven to build your current project, you can use Alibaba Cloud Toolkit to build and deploy your application directly. --File Upload: If you are not using Maven to build your current project, or if you already have a locally packaged deployment file, you can select your local deployment file and upload it directly. --Select ECS to deploy: Select a region from the drop-down list and select the ECS instance to deploy to that region. --Deployment location: Enter the deployment path on the ECS instance. --Command: Enter the application startup command. This parameter specifies the command to run after the deployment is complete. For Node.js programs, this is usually the startup command node XXX.js.
Recommended Posts