[Java] Deploying a Node.js application to an ECS instance using Cloud Toolkit

2 minute read

This article will show you how to deploy a Node.js application on an Alibaba Cloud ECS instance using the Cloud Toolkit.

*This blog is a translation from the English version. You can check the original from here. We use some machine translation. If you find any mistakes in the translation, we would appreciate it if you could point it out. *

In my last article, I explained how to deploy a local Java application directly to an Alibaba Cloud Elastic Compute Service (ECS) instance, which many readers have read. I received your feedback. So to answer your questions, this article will further show you how to deploy a Node.js application to an Alibaba Cloud ECS instance.


Develop application locally

In this article, I will explain the deployment method 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.end('Alibaba Cloud Toolkit: Hello World');
server.listen (port, '', () => {});

The code above is a standard Node.js project for displaying the string “Hello World” on a web page.

Install plugin

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 installation procedure for this Eclipse-based plugin is similar to a typical plugin, so we won’t go into detail here.

Plug-in preferences

After installing the plugin, select it and configure the environment settings.

Top Menu> Window> Preferences> Alibaba Cloud Toolkit> Account

When the following page is displayed, set the AK and SK of your Alibaba Cloud account, and the configuration settings are complete (if you are using a RAM user account, enter the AK and SK of your RAM user. ).


Deploy application

Right-click 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 content:

source ~ / .bash_profile
killall node
nohup node /root/nodejs-demo/helloworld.js >nohup.log 2>&1 &

Placement parameter description

  • Deploy File: There are two options. The optional Upload File is used in Node.js projects.
  • -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’re not using Maven to build your current project, or if you already have a locally packaged deployment file, you can select a 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 start command. This parameter specifies the command to run after the deployment is complete. For Node.js programs, this is usually the launch command node XXX.js.

Alibaba Cloud is a No. 1 cloud infrastructure operator in the Asia Pacific region (2019 Gartner) with two data centers in Japan and more than 60 availability zones in the world. Click here for more information about Alibaba Cloud. Alibaba Cloud Japan Official Page