显示带有对process.env.NODE_ENV条件的日志。

huangapple go评论60阅读模式
英文:

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.

显示带有对process.env.NODE_ENV条件的日志。

英文:

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.

显示带有对process.env.NODE_ENV条件的日志。

答案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

huangapple
  • 本文由 发表于 2023年7月17日 16:43:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76702778.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定