如下:
nodeServer.js
'use strict';
const http = require('http'); const server = http.createServer(function (req, res) {
res.writeHead(, {'Content-Type': 'text/html'});
res.end('Hello World\n');
}); const port = ;
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