'Server port undefined in Node
I am making a Node server and running it so I am getting undefined values from dotenv file.
Here is my project structure:
backend
config
config.env
app.js
server.js
Here is the code of config.js:
PORT = 5000
NODE_ENV = DEVELOPMENT
app.js:
const express = require('express')
const app = express();
module.exports = app
server.js:
const app = require('./app')
const dotenv = require('dotenv');
//setting up confg file
dotenv.config({path:'backend/config/config.env'})
app.listen(process.env.PORT,()=>{
console.log(`server started on PORT:${process.env.PORT} in ${process.env.NODE_ENV} node.`)
})
Here is the output:
server started on PORT:undefined in undefined node.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
