英文:
Show logs with condition on process.env.NODE_ENV
问题
I try to show logs on my ExpressJS app only on the dev
process environment.
In package.json: set NODE_ENV=dev & node index.js
My condition:
server.app.use(function(request, response, next) {
console.log(process.env.NODE_ENV, typeof process.env.NODE_ENV);
if (process.env.NODE_ENV === 'dev') {
console.log(colors.green('URL : ' + request.originalUrl));
}
next();
});
I'm not passing the condition but as you can see above, I'm on the dev
environment.
英文:
I try to show logs on my ExpressJS app only on the dev
process environement.
In package.json : set NODE_ENV=dev & node index.js
My condition :
server.app.use(function(request, response, next) {
console.log(process.env.NODE_ENV, typeof process.env.NODE_ENV);
if (process.env.NODE_ENV === 'dev') {
console.log(colors.green('URL : ' + request.originalUrl));
}
next();
});
I'm not passing the condition but as you can see above, I'm on the dev
environment.
答案1
得分: 1
为了避免环境变量后面的空格,可以将参数设置在括号中。
例如:
(set NODE_ENV=dev) & node index.js
英文:
To avoid trailing spaces for environment variables, the parameter can be set in brackets.
i.e.
(set NODE_ENV=dev) & node index.js
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论