node.js - How to prevent PM2 to change the current directory? -
im using pm2 handle nodejs micro services , express-handlebars handle views:
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 app directly (node app.js) works great. if lunch using pm2 (pm2 start app.js) get:
error: failed lookup view "home" in views directory "/root/views"
when lunching pm2 current working directory change /root/ , since app in not there got error handlebars trying open views directory (which in app directory).
is there way fix telling pm2 current working directory or telling express-handlebars library complete directory instead of using relative one?
i using koa , swig templates - needed include path views in app setup:
app.use(koarender('./server/server-side-views', { map: { html: 'swig' }, cache: false }));
i suspect more of same you. think in express code should along line of:
app.engine('handlebars', hbs.engine); app.set('view engine', 'handlebars'); app.set('views', __dirname + '/yourviewdirectory');
Comments
Post a Comment