The following works if there is something like this in your app.js application:
http.createServer(app).listen(app.get('port'), function(){ console.log("Express server listening on port " + app.get('port')); });
Or explicitly specify the code you want to use, for example:
app.set('port', process.env.PORT || 3000);
This code means that your port matches the PORT environment variable, or if it is undefined , then set it to a literal of 3000 .
Or use the environment to install the port. Configuring it through the environment is used to determine the difference between PRODUCTION and DEVELOPMENT , and many platforms as a service use the environment to set the port in accordance with their specifications, as well as with internal Express configurations. The following sets the environment key pair = value, and then launches your application.
$ PORT=8080 node app.js
Regarding your sample code, you want something like this:
var express = require("express"); var app = express(); // sets port 8080 to default or unless otherwise specified in the environment app.set('port', process.env.PORT || 8080); app.get('/', function(req, res){ res.send('hello world'); }); // Only works on 3000 regardless of what I set environment port to or how I set // [value] in app.set('port', [value]). // app.listen(3000); app.listen(app.get('port'));
EhevuTov Aug 02 '13 at 19:29 2013-08-02 19:29
source share