Node process.env.VARIABLE_NAME returning undefined

nodemon.json file is only for setting nodemon specific configuration
So for create custom environment variables we can use dotenv package

First , Install dotenv package

npm install dotenv --save

after that create .env file in root and include environment variables as bellows

MONGO_ATLAS_PW=xxxxx
JWT_KEY=secret

Finally, inside your app.js file insert following after your imports.

require('dotenv').config()

Then you can use environment varibale like this

process.env.MONGO_ATLAS_PW
process.env.JWT_KEY

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)