Amazon Elastic Beanstalk npm cant find package.json

前端 未结 3 1135
攒了一身酷
攒了一身酷 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

    0 讨论(0)
  • 2021-02-18 21:55

    I was having these odd error on AWS EB as well. I was generally deploying using the CLI.

    couple things to try.

    1. make sure the package.json is not in your .gitignore file, to ensure it is being committed to your repository. EB uses the git commit history to decide what to zip and send. If that isnt included it is not on the AWS servers

    2. i was using the t2.nano instance (512MB space) option for EC and that seemed to be an issue because I had a lot of modules in my package.json. Wasnt sure if that was the root issue of my woes but my error messages changed when I upgraded to an instance that had at least 1GB of space.

    hope this helps

    0 讨论(0)
  • 2021-02-18 22:01

    From an official AWS thread[1], it appears (and this was my problem) that you might be zipping the top-level directory rather than zipping the source itself.

    For example, you may have all of your files in a folder called "Project". Rather than zipping "Project", you should zip and upload the contents of "Project".

    [1] https://forums.aws.amazon.com/thread.jspa?messageID=476022

    0 讨论(0)
提交回复
热议问题