NodeJS 加入windows7服务 开机运行 nssm
发布于 11 年前 作者 jisekai 13697 次浏览 最后一次编辑是 8 年前

首先需要到http://nssm.cc/download/?page=download 下载 nssm

下下来之后是压缩包形式的,解压之后 ctrl + R 进入cmd 命令行界面

在命令行模式下进入到nssm的目录, 注意是32位或64位的系统进入相应的目录。

之后运行:

nssm install NodeJS “\node.exe” “\server.js” net start NodeJS

nssm install NodeJS(安装后的服务名称) “(node.exe安装的地址)\node.exe” “(要启动的JS文件)\server.js” net start NodeJS(安装后的服务名称)

最后要卸载服务用 nssm remove NodeJS(安装后的服务名称)

原文:http://blog.sina.com.cn/u/1593176675

5 回复

装上是可以用,但是日志咋办?

asdfasdfasdf asdf

![Blockquote][1]

var fs = require('fs');

var accessLogfile = fs.createWriteStream('access.log',{flags:'a'});

app.use(express.logger({stream:accessLogfile}));

app.configure('production', function(){

 app.use(function(err,req,res,next){

 var meta = '[' + new Date() + ']' + req.url + '\n';

 errorLogfile.write(meta + err.stack + '\n');

 next();

 });

}); 

可以生成日志!

@jisekai 如果我想实时的监控日志咋办?这种生成的日志用于生产阶段还行,开发阶段看着麻烦

@a272121742 @a272121742 开发阶段就停止服务在命令行下操作,或者用WebStorm

或者设置成开发阶段

app.set('env','development');

然后

app.configure('development', function(){
app.use(express.errorHandler());
}); 
回到顶部