-1

I installed dotenv, created a .env file and wrote PORT = 5000 into it, but for some reason it says that the value in it is undefiend. What is the problem?

File location:

└── src
     ├── index.js
     └── .env
require('dotenv').config();
const express = require('express');

const PORT = process.env.PORT;
const app = express();

app.get('/', (req, res) => {
    res.send("Test");
});

app.listen(PORT, () => {
    console.log(`${PORT} server has been started`);
});
bijoy26
  • 133
  • 9

1 Answers1

0

.env file must be located inside the root directory (on the same level that package.json is located). Not in src

Konrad
  • 21,590
  • 4
  • 28
  • 64