I am facing problem while using dotenv in my project and it showing like 'server is running bro on---> undefined'
require('dotenv').config()
const express= require ('express')
const mongoose=require ('mongoose')
const connectDb = require('./config/config')
const productRoute=require('./routes/ProductRoute')
connectDb()
const app=express()
app.use('/api',productRoute)
const port=process.env.PORT
app.listen(port,()=>{
console.log(`server is running bro on---> ${port}`);
})
I assume you have PORT
defined in your .env
file? I tried out your code, and it works for me.