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
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.
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.
process.env
method of choosing your port number, change your listening port to 80 (or 443 if appropriate).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. :)
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
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.
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.