This document describes how to quickly deploy a local Express project to the cloud through an HTTP-triggered function.
This document mainly describes how to deploy in the console. You can also complete the deployment on the command line. For more information, see Deploying Framework on Command Line.
WebFuncin the search box to filter all HTTP-triggered function templates, select ExpressDemo, and click Next as shown below:
The Node.js runtime environment has been installed locally.
Run the following command to install the Express framework and
express-generator scaffold and initialize the sample Express project.
npm install express --save npm install express-generator --save express WebApp
Run the following command to enter the project directory and install the required dependencies:
cd WebApp npm install
After the installation is completed, run the following command to directly start the service locally.
http://localhost:3000 in a browser, and you can access the sample Express project locally.
You need to make simple modifications to the initialized project, so that the project can be quickly deployed through an HTTP-triggered function. The project transformation here is usually divided into the following two steps:
The detailed directions are as follows:
./bin/wwwfile. If you don't specify it, port 3000 will be listened on by default as shown below:
scf_bootstrapbootstrap file in the project root directory and add the following content to it (which is used to configure environment variables and start services):
755is required for it to start normally. Below is the sample code:
scf_bootstrapdirectory as an example) and make sure that your service can be normally started locally.
After the deployment is completed, you can quickly access and test your web service in the SCF console and try out various features of SCF, such as layer binding and log management. In this way, you can enjoy the advantages of low cost and flexible scaling brought by the serverless architecture as shown below: