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 xxx // 查看所用已启动项目

pm2 restart xxx // 重启

pm2 stop xxx // 停止

pm2 delete xxx // 删除

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

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

猜你喜欢

转载自www.cnblogs.com/xiangsj/p/11262502.html
今日推荐