Nodejs dot env

Ref:

https://medium.com/the-node-js-collection/making-your-node-js-work-everywhere-with-environment-variables-2da8cdf6e786

https://www.npmjs.com/package/dotenv

Install 

npm install dotenv

Read env file

// server.js
console.log(`Your port is ${process.env.PORT}`); // undefined

const dotenv = require('dotenv');
dotenv.config();
console.log(`Your port is ${process.env.PORT}`); // 8626 

Leave a Reply

Your email address will not be published.Required fields are marked *