2020-11-26

Dotenv variables loading but db connection error when variable used

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.

Why is this happening?



from Recent Questions - Stack Overflow https://ift.tt/366uv0E
https://ift.tt/eA8V8J

No comments:

Post a Comment