0

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?

2
  • 1
    EACCESS means that port (8000) is already taken. You can either kill what's on 8000 or choose a different port. Though, given your env variable, are you trying to start a server on the same port as your DB? Commented Nov 26, 2020 at 0:12
  • Sadly not - happens on any port I try. Commented Nov 26, 2020 at 0:15

1 Answer 1

4

It's the semicolon in your .env. You don't terminate lines in a .env file with a semicolon, just a standard line break.

Sign up to request clarification or add additional context in comments.

1 Comment

Amazing - such a simple fix. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.