Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

get port from env in template (fix for #1118) #1127

Merged
merged 2 commits into from

2 participants

Benjamin Atkin TJ Holowaychuk
Benjamin Atkin

I made a change to the app template as suggested in #1118, that gets the port from an environment variable, if it's present. This is used by multiple deployment environments, including Heroku. The updated app template uses an application setting, port, so it can be used elsewhere as well.

TJ Holowaychuk

we can use app.get('port') now in 3.x as well haha so it actually makes sense now :D

ooh, nice! updated; sending pull request

TJ Holowaychuk tj merged commit 9da3e9c into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 3 deletions.
  1. +4 −3 bin/express
7 bin/express
View
@@ -181,6 +181,7 @@ var app = [
, 'var app = express();'
, ''
, 'app.configure(function(){'
+ , ' app.set(\'port\', process.env.PORT || 3000);'
, ' app.set(\'views\', __dirname + \'/views\');'
, ' app.set(\'view engine\', \':TEMPLATE\');'
, ' app.use(express.favicon());'
@@ -197,9 +198,9 @@ var app = [
, ''
, 'app.get(\'/\', routes.index);'
, ''
- , 'http.createServer(app).listen(3000);'
- , ''
- , 'console.log("Express server listening on port 3000");'
+ , 'http.createServer(app).listen(app.get(\'port\'), function() {'
+ , ' console.log("Express server listening on port " + app.get(\'port\'));'
+ , '});'
, ''
].join(eol);
Something went wrong with that request. Please try again.