Simple creation of a KOA2 project to server deployment,
In this example, centos is used.
Create a KOA2 project
npm install -g koa-generator
Copy the code
NPM start is NPM run start NPM stop is NPM run stoptestNPM is runtestNPM restart is short for NPM run stop && NPM run restart && NPM run startCopy the code
Deployment (Centos)
- Log in to the server:
SSH -p 22 at [email protected]Copy the code
- Upload the project to the server and install the dependencies
npm install
Copy the code
You can test the project by NPM run start
However, when we exit the server, the Node process shuts down and the service is gone,
So we need pM2 for the daemon
- Install the pm2
npm install pm2 -g
Copy the code
After installation, switch the cloud service to the path of your project
- Start and listen to the service:
pm2 start ./bin/www --watch
## -- Watch parameter, pM2 will help you restart service when koA2 application code changes.
Copy the code
If the following information is displayed, the startup is successful.
- Pm2 more
Pm2 start./bin/ WWW // pm2 stop./bin/ WWW // pm2 list //
Pm2 list View, pM2 list
Enter pm2 show 0 for id = 0 in the preceding figure
Pm2 Kills a process