简体   繁体   中英

How to deploy nodejs expressjs app in Azure with CI/CD?

I'm trying to deploy a nodejs with expressjs app. My pipeline is this:

在此处输入图像描述

This create a correct artifact:

在此处输入图像描述

We can check here:

在此处输入图像描述

Now I create this release that uses the artifact I mentioned previously:

在此处输入图像描述

The steps in release:

在此处输入图像描述

And after release executed(success) in appname.scm.azurewebsites.net in wwwroot folder I have the right files:

在此处输入图像描述 But application never start because I never tell how start I think.

What would I put in Post deployment action? node server/server.js? (server.js is in server folder), npm start? In my package.json if I use npm start, then it going to run node server/server.js. Because in local, if I will run my app I have to execute npm start or node server/server.js

In the package.json file, normally you set the main file, "main": "server.js" , in your case I think you should define main as "main": "server.js" and move the server.js file from the server directory to project root directory .

If you look at the log stream, normally to start the project, azure runs node server or something you defined in the package.json as main.

I have pasted some parts of the azure log stream here so you can see what happens in the azure:

2022-05-09T18:19:04.222521897Z # Enter the source directory to make sure the script runs where the user expects
2022-05-09T18:19:04.222528898Z cd "/home/site/wwwroot"
2022-05-09T18:19:04.222535898Z
2022-05-09T18:19:04.222542298Z export NODE_PATH=/usr/local/lib/node_modules:$NODE_PATH
2022-05-09T18:19:04.222548498Z if [ -z "$PORT" ]; then
2022-05-09T18:19:04.222554799Z      export PORT=8080
2022-05-09T18:19:04.222561899Z fi
2022-05-09T18:19:04.222783509Z
2022-05-09T18:19:04.222805710Z node server.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM