Pagoda deployment nodejs project

foreword

The deployment operation is very simple, and there are many tutorials on the Internet, but I still stepped on the pit, so I will record it here, so that others can avoid the pit.

step

First of all, you already have a server and opened the pagoda panel, and then prepare your nodejs project.
Install the pm2 manager in the Pagoda (recommended)
insert image description here
Open the pm2 settings, select the version corresponding to the nodejs project,
insert image description here
click on the left menu 文件, click on the root directory www, where wwwrootis 默认建站目录
insert image description here
the new directory of the pagoda nodejs-demo
insert image description here
, enter the folder, and upload your nodejs project. Note: I stepped on the pit here, and uploaded node_modules compressed and uploaded according to a certain article. It is recommended to ignore node_modules and upload other files, and then open the pagoda built-in terminal to install dependencies, 务必使用对应的包管理工具, I am pnpm here. If you use non-npm tools, remember to download the corresponding tools in the module management of pm2.
insert image description here
After the installation is complete, click Refresh on the right side of the directory to see node_modules
insert image description here
. The next step is to release the port. If you do not release it, you will not be able to access it. Here you need to release two places, the security menu of the pagoda panel and the firewall of the cloud server. My project If the port is 3000, let 3000
insert image description here
insert image description here
go back to the pagoda panel, open the pm2 manager, and add the project.
insert image description here
After the project is successfully added, the corresponding port will be displayed, and the status will be a green play icon. If the port number is not displayed, the project must have failed to start. It is recommended to restart Go through the process.
insert image description here
At this point, you can enter in the browser ip/域名:端口号to access the node project
insert image description here

other

Here I will talk about the pitfalls I encountered in detail. I compressed and packaged node_modules according to a certain article. After decompressing the pagoda, I went to the step of adding projects in pm2, and then the port number could not be displayed. I went back and forth several times after deleting the project > adding the project. It was useless, and later changed to other articles saying that dependencies should be installed in the pagoda, so I deleted the compressed and uploaded node_modules and reinstalled. But here I am stupid. The pnpm and pnpm-lock files used in my project are also uploaded together, but I use npm to reinstall the dependencies, but the result is still not working. At this time, I haven't found the previous problem. I checked the error log in pm2, and the log indicated that express could not be found. I was very puzzled. It was installed in node_modules, but there must be a problem with the log error. I opened the online and local dependency packages on the pagoda and vscode respectively. After a comparison, I found that the structure was different. Only then did I feel the problem. , look at the pagoda, there are two lock files of npm and pnpm. Delete node_modules, delete the npm lock file, then install pnpm, install dependencies with pnpm, and finally successfully add the node project. Having said that, it turned out that I was too careless (laughing and crying), I hope other people will not make me such a fool.

Guess you like

Origin blog.csdn.net/sunddy_x/article/details/125279277