I am trying to set my environment variable within package.json so that I can use it within my server.js file. I have set it as NODE_ENV=development
, set NODE_ENV=development
,
cross-env NODE_ENV=development
, export NODE_ENV=development
but it is still returning undefined. I am not sure what is going wrong but I would love any insight into this problem!
package.json
"scripts": {
"dev": "NODE_ENV=development npm run client & npm run start & npm run json-server & redis-server"
}
server.js
//returns undefined
console.log(process.env.NODE_ENV)
2
Answers
Did you install and require the dotenv package and did you call the .config() function of it in your index.js ? This will probably help.