As a currently popular Web service development language, Node.js provides many related functions that support HTTP scenarios, which can be said to be born for Web construction. Therefore, based on Node.js, a variety of web service frameworks have also been born. They extend the content of Node.js and focus on the direct construction and development of web services, such as Express, Koa, etc., and become the first in the development of web services. Preferred.
The release of the cloud function Web Function also brings a new solution for developers to upload web services to the cloud. Simply modify the listening port to directly deploy the currently popular Node.js framework to the cloud and enjoy the benefits of Serverless technology. Many advantages of free operation and maintenance, low cost, and expansion and contraction on demand.
This document will guide you how to quickly deploy your local Express project to the cloud through Web Function.
01. Template deployment-no need to change business code, one-click deployment
- Log in to the Serverless console, click "Function Service" in the left navigation bar, select the region where you want to create a function at the top of the main interface, and click "New" to enter the function creation process.
- Choose to use "Template Creation" to create a new function, enter " WebFunc " in the search box, filter all Web function templates, select the Express framework template, and click "Next", as shown in the following figure:
- On the "Configuration" page, you can view and modify the specific configuration information of the template project;
- Click " complete " to create the function. After the function is created, you can view the basic information of the Web function on the "Function Management" page, and access it through the access path URL generated by the API gateway to view your deployed Express project.
02. Custom deployment-3 steps to quickly migrate local projects to the cloud
1. Local development
- First, after ensuring that your local Node.js runtime environment has been installed, install the Express framework and express-generator scaffolding, and initialize your Express sample project
npm install express --save
npm install express-generator --save
express WebApp
- Enter the project directory, install the dependency package
cd WebApp
npm install
- After the installation is complete, start directly locally, and visit
http://localhost:3000
in the browser to complete the access to the Express sample project locally
npm start
2. Deploy to the cloud
Next, we make simple modifications to the initialized project so that it can be quickly deployed through Web Function. The project transformation here is usually divided into two steps:
- Modify the listening address and port to
0.0.0.0:9000
- Add
scf_bootstrap
startup file
Specific steps are as follows:
- It is known that in the Express sample project, the
./bin/www
. Open the file and you can find that we can set the specified listening port through environment variables, otherwise it will automatically monitor3000
- Next, create a new
scf_bootstrap
startup file in the project root directory, configure environment variables in it, and specify the service startup command
#!/bin/bash
export PORT=9000
npm run start
After creation, pay attention to modify your executable file permissions. By default, 777
or 755
permissions are required to start normally
chmod 777 scf_bootstrap
- After the local configuration is complete, execute the startup file to ensure that your service can be started normally locally. Next, log in to the Tencent Cloud Cloud Function Console and create a new Web function to deploy your Express project:
3. Development Management
After the deployment is complete, you can quickly access and test your web services on the SCF console, and experience multiple features of cloud functions such as layer binding, log management, etc., and enjoy the low cost, flexible expansion and contraction brought by the serverless architecture, etc. Advantage.
Web Function experience
Web Function product documentation:
Web Function quick experience link:
https://console.cloud.tencent.com/scf/list-create?rid=16&ns=default&keyword=WebFunc
Web Function is currently being released in the "Chengdu Region" gray scale, and other regions will be opened one after another, so stay tuned!
One More Thing
Experience Tencent Cloud Serverless Demo now and receive the Serverless new user gift pack Tencent Cloud Serverless newbie experience .
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。