搜索
您的当前位置:首页正文

Windows下node自启动,开机启动

来源:二三娱乐

安装pm2:npm install -g pm2
查看pm2版本:pm2 -v
查看服务列表:pm2 list
启动服务:pm2 start 你的文件

pm2示例

下边就可以做自启动和开机启动了。

编写一个pm2启动服务的批处理文件

@echo off
pm2 start   D:\node\serviceDemo.js

我这里是同时启动上边示例图片中的两个服务。

将写好的批处理文件放在下边的路径下,就会开机自启了

C:\Users\当前登录用户名\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
批处理文件放置位置

serviceDemo.js文件,网上随便一搜就是这个代码

var http = require('http');
http.createServer(function(request,response){
    response.writeHead(200,{'Content-Type':'text/plain'})
    response.end('Hello world\n');
}).listen(8888);

console.log('Server runnint at http:localhost:8888');

如果修改了文件需要手动重启服务
运行效果:

运行效果
Top