xxxxxxxxxx
// 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
xxxxxxxxxx
First of all run this in your terminal
npm i dotenv
then on the top of your main file
require("dotenv").config();
and then u can use your env vars like
process.env.DISCORD_JS_BOT_TOKEN
xxxxxxxxxx
console.log(app.get('env'))
if(app.get('env').toLowerCase()==="development"){
app.use(morgan("dev"))
}