D
D
Dmitry2021-04-01 13:22:03
Software Deployment
Dmitry, 2021-04-01 13:22:03

Why is Error: listen: EPERM 3000 thrown when running Nodejs in production?

I created a project on Node.js, (koa) uploaded it to the server on the run.
In app.js, these are the server listening lines

var port = 3000
app
    .use(authRoutes_1.default.routes())
    .use(keysRoutes_1.default.routes())
    .use(exchangesRoutes_1.default.routes())
    .use(wishlistRoutes_1.default.routes())
    .listen(port, function () { console.log('Listening on port ' + port); });

When opening the site, an error is generated Error: listen: EPERM 3000, such as there is no access to port 3000.

I created a simple example of a server on a node that also listens on port 3000 and issues a simple message

var http = require('http');
var server = http.createServer(function(req, res) {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World!');
});
server.listen(3000);


Works great.
Is it possible to somehow get to the bottom of what causes a similar error in my case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
ZB Venom, 2021-04-02
@zb_venom

To publish a project on a hosting, you should use the following port initialization:
const PORT = process.env.PORT || 3000

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question