Closed
Bug 795233
Opened 13 years ago
Closed 13 years ago
node/express "hello world" does not seem to work
Categories
(Petri Graveyard :: General, defect)
Petri Graveyard
General
Tracking
(Not tracked)
RESOLVED
INVALID
People
(Reporter: rhelmer, Unassigned)
References
Details
While debugging etherpad-lite failing to start up (even though the log output looks fine), I decided to try the "hello world" example from the docs:
http://docs.cloudfoundry.com/frameworks/nodejs/nodejs.html
```
$ cat package.json
{
"name":"hello-node",
"version":"0.0.1",
"dependencies":{
"express":""
}
}
$ cat app.js
var app = require('express').createServer();
app.get('/', function(req, res) {
res.send('Hello from Cloud Foundry');
});
app.listen(3000);
$ vmc push
Would you like to deploy from the current directory? [Yn]:
Application Name: hello-node
Application Deployed URL [hello-node.vcap.mozillalabs.com]:
Detected a Node.js Application, is this correct? [Yn]:
Memory Reservation (64M, 128M, 256M, 512M, 1G) [64M]:
Creating Application: OK
Would you like to bind any services to 'hello-node'? [yN]:
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (18K): OK
Push Status: OK
Staging Application: OK
Starting Application: ..........................
Error: Application [hello-node] failed to start, logs information below.
====> logs/stderr.log <====
Warning: express.createServer() is deprecated, express
applications no longer inherit from http.Server,
please use:
var express = require("express");
var app = express();
Delete the application? [Yn]:
```
If I run the app.js locally I get the deprecation warnings, but it does work fine.
Comment 1•13 years ago
|
||
(In reply to Robert Helmer [:rhelmer] from comment #0)
> While debugging etherpad-lite failing to start up (even though the log
> output looks fine), I decided to try the "hello world" example from the docs:
>
> http://docs.cloudfoundry.com/frameworks/nodejs/nodejs.html
>
> ```
> $ cat package.json
> {
> "name":"hello-node",
> "version":"0.0.1",
> "dependencies":{
> "express":""
> }
> }
>
> $ cat app.js
> var app = require('express').createServer();
> app.get('/', function(req, res) {
> res.send('Hello from Cloud Foundry');
> });
> app.listen(3000);
>
>
> $ vmc push
> Would you like to deploy from the current directory? [Yn]:
> Application Name: hello-node
> Application Deployed URL [hello-node.vcap.mozillalabs.com]:
> Detected a Node.js Application, is this correct? [Yn]:
> Memory Reservation (64M, 128M, 256M, 512M, 1G) [64M]:
> Creating Application: OK
> Would you like to bind any services to 'hello-node'? [yN]:
> Uploading Application:
> Checking for available resources: OK
> Processing resources: OK
> Packing application: OK
> Uploading (18K): OK
> Push Status: OK
> Staging Application: OK
>
> Starting Application: ..........................
> Error: Application [hello-node] failed to start, logs information below.
>
> ====> logs/stderr.log <====
>
> Warning: express.createServer() is deprecated, express
> applications no longer inherit from http.Server,
> please use:
>
> var express = require("express");
> var app = express();
>
>
>
> Delete the application? [Yn]:
> ```
>
> If I run the app.js locally I get the deprecation warnings, but it does work
> fine.
Did you use the 'node' or the 'node06' runtimes ? By default, our current cloudfoundry setup uses a somewhat dated version of node, if you use
$> vmc push --framework node06 [...]
You'll run your app under a much newer version of node.js. Can you try that first ?
| Reporter | ||
Comment 2•13 years ago
|
||
Same deal:
```
$ vmc push --runtime node06
Would you like to deploy from the current directory? [Yn]:
Application Name: hello-world
Application Deployed URL [hello-world.vcap.mozillalabs.com]:
Detected a Node.js Application, is this correct? [Yn]:
Memory Reservation (64M, 128M, 256M, 512M, 1G) [64M]:
Creating Application: OK
Would you like to bind any services to 'hello-world'? [yN]:
Uploading Application:
Checking for available resources: OK
Processing resources: OK
Packing application: OK
Uploading (15K): OK
Push Status: OK
Staging Application: OK
Starting Application: ..........................
Error: Application [hello-world] failed to start, logs information below.
====> logs/stderr.log <====
Warning: express.createServer() is deprecated, express
applications no longer inherit from http.Server,
please use:
var express = require("express");
var app = express();
Delete the application? [Yn]:
Deleting application [hello-world]: OK
```
Comment 3•13 years ago
|
||
Sorry, the reason was just too obvious for me to spot it. In CloudFoundry land, the node.js app must bind on a port that's provided by CloudFoundry. Not a hard-coded port 3000.
So, the small change to make is :
[...]
var port = process.env.VMC_APP_PORT || 3000;
app.listen(port);
| Reporter | ||
Comment 4•13 years ago
|
||
(In reply to Philippe M. Chiasson (:gozer) from comment #3)
> Sorry, the reason was just too obvious for me to spot it. In CloudFoundry
> land, the node.js app must bind on a port that's provided by CloudFoundry.
> Not a hard-coded port 3000.
>
> So, the small change to make is :
>
> [...]
> var port = process.env.VMC_APP_PORT || 3000;
> app.listen(port);
Ah ok that makes sense (that's how heroku works too), thanks!
Would be nice if the docs I linked to mentioned it, presumably it's somewhere in there and I missed it.
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → WORKSFORME
| Reporter | ||
Updated•13 years ago
|
Resolution: WORKSFORME → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•