question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

config.prod.js value is not being used when NODE_ENV is production.

See original GitHub issue

When I set the key/value in config.default.js, it will work in any environment.

If I separated key/value into config.local.js and config.prod.js with different value on the same key, it will read the key/value in development mode just fine, but not in config.prod.js.

To reproduce it,

// config.local.js
...
rest: {
  username: 'matt',
},
...

When I console log the this.app.config.rest.username inside app/apis/demo.js * index() function, I can get the value of ‘matt’. In this case, the value of this.app.env is development

// config.prod.js
...
rest: {
  username: 'matt_prod',
},
...

If I start the server with NODE_ENV=production npm start, When I console log the this.app.config.rest.username inside app/apis/demo.js * index() function, I can get the value of ‘undefined’. In this case, the value of this.app.env is production. So it is not reading the value from config.prod.js. Also tried with NODE_ENV=prod npm start. it does not work either.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mattmacommented, Sep 11, 2016

something like,

if you want to run Egg server in production mode, you may run a NPM script like this

...
'prod': NODE_ENV=production EGG_SERVER_ENV=prod npm start
...

To start your server in production, try this in terminal

npm run prod
0reactions
atian25commented, Sep 10, 2016

所以这个的结论就是补文档?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NODE_ENV not set on process.env · Issue #2362 · webpack ...
I was very surprised that --mode=production doesn't set process.env.NODE_ENV with value production within webpack.config.js but only ...
Read more >
Can't Set NODE_ENV to production with webpack
In my webpack.config.js, I replaced the option for the DefinePlugin to 'process.env.NODE_ENV': '"production"' and it worked.
Read more >
Do not use NODE_ENV for staging - Gleb Bahmutov
I often use NODE_ENV environment variable to flag these three environments. ... Thus staging will NOT be exactly like production.
Read more >
Working with Environment Variables in Node.js - Twilio
This script will now execute npm run start:prod and subsequently node. If NODE_ENV has the value production, it will then be able to...
Read more >
Node.js, the difference between development and production
js that you are running in production by setting the NODE_ENV=production environment variable. This is usually done by executing the command. BASH copy....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found