节点配置没有';使用节点窗口将应用程序设置为Windows服务时,无法读取配置文件
我正在使用将我的应用程序设置为作为Windows服务运行。我正在使用管理配置设置。当然,当我使用节点配置没有';使用节点窗口将应用程序设置为Windows服务时,无法读取配置文件,windows,node.js,Windows,Node.js,我正在使用将我的应用程序设置为作为Windows服务运行。我正在使用管理配置设置。当然,当我使用node-app.js命令手动运行应用程序时,一切都正常。当我将其作为服务安装并启动时,配置设置为空。我在/config文件夹中有production.json文件,我可以在安装脚本中将NODE\u ENV设置为production。我可以确认变量设置正确,但仍然是空的log.info('CONFIG\u DIR:'+CONFIG.util.getEnv('CONFIG\u DIR'))生成未定义的,
node-app.js
命令手动运行应用程序时,一切都正常。当我将其作为服务安装并启动时,配置设置为空。我在/config
文件夹中有production.json
文件,我可以在安装脚本中将NODE\u ENV
设置为production。我可以确认变量设置正确,但仍然是空的log.info('CONFIG\u DIR:'+CONFIG.util.getEnv('CONFIG\u DIR'))代码>生成未定义的
,即使我在服务的env
值中显式设置了它。寻找任何洞察力
安装脚本:
var Service = require('node-windows').Service;
var path = require('path');
// Create a new service object
var svc = new Service({
name:'Excel Data Import',
description: 'Excel Data Import Service.',
script: path.join(__dirname, "app.js"), // path application file
env:[
{name:"NODE_ENV", value:"production"},
{name:"CONFIG_DIR", value: "./config"},
{name:"$NODE_CONFIG_DIR", value: "./config"}
]
});
// Listen for the "install" event, which indicates the
// process is available as a service.
svc.on('install',function(){
svc.start();
});
svc.install();
应用程序脚本:
var config = require('config');
var path = require('path');
var EventLogger = require('node-windows').EventLogger;
var log = new EventLogger('Excel Data Import');
init();
function init() {
log.info("init");
if(config.has("File.fileFolder")){
var pathConfig = config.get("File.fileFolder");
log.info(pathConfig);
var DirectoryWatcher = require('directory-watcher');
DirectoryWatcher.create(pathConfig, function (err, watcher) {
//...
});
}else{
log.info("config doesn't have File.fileFolder");
}
}
我知道这个回复很晚了,但我也遇到了同样的问题,我是如何解决的:
var svc = new Service({
name:'ProcessName',
description: 'Process Description',
script: require('path').join(__dirname,'bin\\www'),
env:[
{name: "NODE_ENV", value: "development"},
{name: "PORT", value: PORT},
{name: "NODE_CONFIG_DIR", value: "c:\\route-to-your-proyect\\config"}
]
});
使用windows时,不需要在环境变量前加$
此外,当运行脚本与配置目录不在同一目录上时,必须提供配置目录的完整路径
当节点窗口出现错误时,深入查看错误日志也很有帮助。它位于rundirectory/daemon/processname.err.log上
我希望这能帮助别人