Express is a web framework that is provided to facilitate efficient development of Node.js applications. You can use Express to develop API-based applications, Web applications, backend applications, and other applications. This topic describes how to develop a simple Express application and deploy the application in Web+.
A Node.js environment is configured. For more information, see Configure a Node.js development environment.
Step 1: Install express-generator
npm install -g express-generator
Step 2: Create an application.
npx express-generator webplus-express-appcommand to run express-generator. You do not need to manually install express-generator.
Step 3: Install local dependencies
- Use the following command to go to the webplus-express-app directory.
- Use the following command to install local dependencies.
Step 4: Start the application on the localhost
- Use the following command to start the application on the localhost. Check whether
the application performs as expected.
npm startA successful start of the application is indicated if the following message is displayed on the command prompt.
> firstname.lastname@example.org start /home/admin/webplus-express-app > node ./bin/www
- View the result.
- Open a browser and enter http://localhost:3000 in the address bar to visit the homepage of the application.
- Use the curl http://localhost:3000 command to view the result that is returned.
<! DOCTYPE html> <html> <head> <title>Developer Guide</title> <link rel="stylesheet" href="/stylesheets/style.css"> </head> <body> <h1>Express</h1> <p>Welcome to Express</p> </body> </html>Note The original message is displayed by using single-line text. However, the returned message provided here is formatted for readability.
- You can press CTRL+C to stop the service after viewing the running result of the application.
Step 5: Package the application
zip -r webplus-express-app.zip .
Step 6: Deploy the application in Web+
- Log on to the Web+ console.
- On the Overview page, click Create in the upper-right corner of the Last Updated Deployment Environments section.
- In the Basic Information step, select Node.js in the Technology Stack Type field, enter an application name and description, and then click Next.
- In the Deployment Environment Information step, enter a deployment environment name, select Upload Local Application in the Deployment Package Source field, upload the webplusdemo.zip deployment package, modify the package version, and click Create with Low Cost Preset.
- In the Creation Complete step, click View Application or Creation Complete to go to the Overview tab of the Application Details page. Click the name of a deployment environment to go to the Overview tab of the Deployment Environment Details page. Then, click the link next to the Public IP Address label to visit the homepage of the application.
- To view a demo about how to deploy an application in Web App Service, see Create an application and deployment environment in Web App Service.
- For more information about how to deploy an application in the console, see Deploy an application.
- For more information about how to use the CLI tool to create and deploy an application, see Use the CLI tool to deploy an application.
- For more information about how to manage hosted applications, see Overview of application details.
- For more information about how to manage deployment environments where applications reside, see Overview of deployment environments.