[英]How to prevent PM2 to change the current directory?
Im using pm2 to handle my nodejs micro services and express-handlebars to handle the views: 即时通讯使用PM2来处理我的微的NodeJS服务和快递车把处理意见:
var hbs = exphbs.create({
defaultLayout: 'main',
helpers: {
ifeq: function(a, b, options) {
if (a === b) {
return options.fn(this);
}
return options.inverse(this);
},
toJSON : function(object) {
return JSON.stringify(object);
}
}
});
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
Lunching the app directly (node app.js) works great. 直接启动应用程序(节点app.js)非常有用。 But if I lunch it using PM2 (pm2 start app.js) i get:
但如果我使用PM2(pm2 start app.js)午餐,我会得到:
Error: Failed to lookup view "home" in views directory "/root/views"
错误:无法在视图目录“/ root / views”中查找视图“home”
When lunching pm2 the current working directory change to /root/ and since my app in not there I got an error from handlebars trying to open the views directory (which is in the app directory). 午餐时pm2当前工作目录更改为/ root /并且由于我的应用程序不在那里,我从车把试图打开视图目录(位于app目录中)收到错误。
Is there a way to fix this by telling pm2 the current working directory or by telling the express-handlebars library the complete directory instead of using a relative one? 有没有办法通过告诉pm2当前工作目录或通过告诉express-handlebars库完整目录而不是使用相对目录来解决这个问题?
I am using Koa and SWIG for templates - but I needed to include the path to the views in the app setup: 我使用Koa和SWIG作为模板 - 但我需要在应用程序设置中包含视图的路径:
app.use(koaRender('./server/server-side-views', {
map: { html: 'swig' },
cache: false
}));
I suspect it is more of the same for you. 我怀疑你的情况更为相似。 I think in express your code should be something along the line of:
我认为在快递中你的代码应该是这样的:
app.engine('handlebars', hbs.engine);
app.set('view engine', 'handlebars');
app.set('views', __dirname + '/yourViewDirectory');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.