Amazon Elastic Beanstalk npm cant find package.json

前端 未结 3 1134
攒了一身酷
攒了一身酷 2021-02-18 21:12

I\'m very new with amazon web services, and I am trying to set up a node.js app on their elastic beanstalk. I set up the instance and uploaded/deployed the site, but while the h

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-18 21:55

    I had a problem the same as - or very similar to this, and it was caused the fact that my code was listening to a custom port, instead of the one that Elastic Beanstalk sets as an environment variable (8081).

    I fixed this setting in the port near top of my app.js or server.js file, just after I create the express app. For example:

    var app = express();
    app.set('port', (process.env.PORT || 5000)); // 5000 was my original port
    

    Then using this port in the app.listen method instead of my own custom port number:

    app.listen(app.get('port'), function () {
        console.log('Server has started! http://localhost:' + app.get('port') + '/');
    });
    

    More details here: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_nodejs.container.html#nodejs-platform-proxy

提交回复
热议问题