pm2 工具来管理 node 服务端

如下:

nodeServer.js

'use strict';
const http = require('http');

const server = http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/html'});
    res.end('Hello World\n');
});

const port = 8361;
server.listen(port);

console.log(`Server is running at http://127.0.0.1:${port}/`);

 

node nodeServer

 

下面用pm2管理,及常用

pm2 start nodeServer.js // 启动管理

pm2 list // 或者 pm2 l 简写 // 查看所用已启动项目

pm2 restart xxx // 重启

pm2 stop xxx // 停止

pm2 delete xxx // 删除

 

当然也可配置json文件,来启用管理

PM2 文档: http://pm2.keymetrics.io/docs/usage/quick-start/#usage

 

posted @ 2019-07-29 10:32  James2019  阅读(437)  评论(0编辑  收藏  举报