Has anyone been successful deploying a node (express) app with Amazon OpsWorks?

前端 未结 5 1828
生来不讨喜
生来不讨喜 2021-02-05 14:40

As the title suggested, I\'ve been playing around deploying apps with Amazons new OpsWorks management system, however I haven\'t been able to figure out how to get the node serv

相关标签:
5条回答
  • 2021-02-05 15:13

    Just copying the AWS OpsWorks page for configuring the node.js app:

    "By default we expect your Node.js app to listen on port 80. Furthermore, the file we pass to node has to be named "server.js" and should be located in your app's root directory."

    Regards.

    0 讨论(0)
  • 2021-02-05 15:24

    The amount of time I spent on this is embarrassing, but I will share anyway in hopes of saving other people the hours of their lives that would otherwise be stolen by Amazon.

    • To answer your question, yes, I did get my node/express application running.
    • In case you were using any kind of process.env method of choosing your port number, change your listening port to 80 (or 443 if appropriate).
    • Most importantly, Amazon doesn't care what your main file is. Rename it server.js and have it in the root directory of your application. That is the file that monit tries to run.

    Hopefully that helps. If it doesn't, or if all of that is obvious, I apologize for my silliness and blame lack of sleep. :)

    0 讨论(0)
  • 2021-02-05 15:33

    I played around this for a bit as well and hopefully my path to success will help someone. Node.js usually needs elevated privileges to run on port 80 so I discovered that while naming the sample app app.js was fine, you need to modify line 2 of the default OpsWorks Node.js deploy chef recipe to use sudo:

    • AWS Original: https://github.com/aws/opsworks-cookbooks/blob/master/opsworks_nodejs/templates/default/node_web_app.monitrc.erb#L2

    • Modified: https://github.com/nationalfield/opsworks-cookbooks/blob/master/opsworks-nodejs/templates/default/node_web_app.monitrc.erb#L2

    0 讨论(0)
  • 2021-02-05 15:35

    A bit off topic maybe, but I spent a couple of hours on this so I figured it's worth sharing:

    When setting up a Hapi.js server on OpsWorks, I had to ensure that I didn't use hostname localhost, but instead set it to 0.0.0.0. Otherwise it just kept failing silently.

    Hope that helps anyone.

    0 讨论(0)
  • 2021-02-05 15:36

    Great answer from ZachRabbit. I'd just like to add that OpsWorks now supports setting of environment variables (i.e. process.env.PORT) for the deployed application process.

    When you Add App (or edit) you can go ahead and set up an environment variable with a key of PORT and a value of 80 if you're using something like the following in your server.js:

    !/usr/bin/env node
    var debug = require('debug')('my-app');
    var app = require('app');
    
    app.set('port', process.env.PORT || 3000);
    
    var server = app.listen(app.get('port'), function() {
      debug('Express server listening on port ' + server.address().port);
    });
    

    More information on the setting of the environment variables can be found here:

    http://docs.aws.amazon.com/opsworks/latest/userguide/apps-environment-vars.html

    Ensuring that the filename was server.js and setting the environment variable PORT to 80 worked like a champ for me.

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