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

前端 未结 5 1838
生来不讨喜
生来不讨喜 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: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.

提交回复
热议问题