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?
EACCESSmeans that port (8000) is already taken. You can either kill what's on8000or choose a different port. Though, given your env variable, are you trying to start a server on the same port as your DB?