Testing to see if dotenv is working and I have the following:
.env
DB_PORT = 8000;
server.js
import dotenv from 'dotenv';
dotenv.config();
....
const PORT = process.env.DB_PORT || 8001;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}.`);
});
If I run this I get the error (although it shows the varible is loading):
Error: listen EACCES: permission denied 8000;
Change the port and the same thing:
Error: listen EACCES: permission denied 3000;
If I comment out DB_PORT in the .evn file it works on 8001. If I leave it commented out and enter the following in the VS Code terminal:
export DB_PORT = 3600;
it runs on 3600.
Why is this happening?
It's the semicolon in your .env
. You don't terminate lines in a .env
file with a semicolon, just a standard line break.