我试图在node-webkit中永远监视工作。我过去在节点快递应用程序中使用它没有任何问题,但似乎无法在这种情况下使其工作。
我有一个index.html文件,该文件引用了server.js脚本,该脚本包含在启动时执行的以下代码:
var forever = require('forever-monitor');
var child = new (forever.Monitor)('app.js', {
max: 3,
silent: false,
options: []
});
child.on('exit', function () {
console.log('app.js has exited after 3 restarts');
});
child.on('start', function () {
console.log('app.js has started');
});
child.on('restart', function (){
console.log('app.js restarted');
});
child.start();
app.js文件包含以下代码:
var Q = require('q'),
gui = require('nw.gui'),
express = require('express'),
path = require('path'),
fs = require('fs'),
Config = require('./api/utils/config'),
SessionService = require('./api/services/SessionService'),
menu = new gui.Menu(),
exec = require('child_process').exec,
child;
var app = express();
var trayActive = false;
var tray;
var routePath = path.resolve('./api/controllers'); // Dynamically pull in all routes and pass in application
app.use(express.cookieParser());
app.use(express.json());
app.use(express.urlencoded());
fs.readdirSync(routePath).forEach(function (file) {
var filePath = path.join(routePath, file);
require(filePath)(app, openFile);
});
var server = app.listen(Config.expressPort, function () {
console.log('Listening on port: ', server.address().port);
gui.Window.get().show();
});
当我开始' npm开始'我得到以下输出:
[970:0602/191500:INFO:CONSOLE(15)]"" app.js有 开始"",来源: file:///Users/chris/webstorm-projects/myapp/server.js(15)execvp(): 没有这样的文件或目录
非常感谢任何见解,如果您知道在node-webkit中完成重新启动的工作替代方法,请告诉我。感谢。
答案 0 :(得分:0)
对于我的情况,我无法要求(' nw.gui')