Here is my setup:
I am working through the tutorial found at http://www.nodebeginner.org
Manuel shows how to create a custom module called server.js:
var http = require("http");
function start() {
function onRequest(request, response) {
console.log("Request received.");
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World");
response.end();
}
http.createServer(onRequest).listen(8888);
console.log("Server has started.");
}
exports.start = start;
He shows how to reference this custom module from index.js:
var server = require("./server");
server.start();
I tried running the index.js in the cloud9 ide but it hangs or gives me a Service Temporarily Unavailable error. I thought it might be an issue with cloud9, so I pushed it to my Heroku instance. From Heroku, I receive an Application Error page. The Heroku logs show:
←[33m2012-08-13T19:03:19+00:00 heroku[slugc]:←[0m Slug compilation finished
←[35m2012-08-13T19:03:21+00:00 heroku[web.1]:←[0m Starting process with command `node index.js`
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Object.<anonymous> (/app/index.js:1:70)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Module._compile (module.js:446:26)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Object..js (module.js:464:10)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m Error: require.paths is removed. Use node_modules folders, or the NODE_PATH environment variable instead.
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Function.<anonymous> (module.js:383:11)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Module.load (module.js:353:31)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Function._load (module.js:311:12)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at Array.0 (module.js:484:10)
←[35m2012-08-13T19:03:21+00:00 app[web.1]:←[0m at EventEmitter._tickCallback(node.js:190:38)
←[35m2012-08-13T19:03:23+00:00 heroku[web.1]:←[0m Process exited with status 1
←[35m2012-08-13T19:03:23+00:00 heroku[web.1]:←[0m State changed from starting to crashed
I googled it and found questions relating to a local cloud9 install, but nothing on the hosted version. I also tried moving server.js from the root to the node_modules folder, but can't seem to get it to work. My first step was to get the standard 'Hello World' app up and running to prove out the debug mode and the heroku deployment and it all worked fine. It's the custom module I am having difficulties with.
Any help is appreciated. Thanks!
The reason it doesn't run on Cloud9 is because you listen to port 8888
instead of process.env.PORT
.
The heroku error that you show is a different kind of error which complains about the removal of the require.paths
function, which was removed in node 0.4.x. So that's something completely different. Are you sure you are watching the right log file? Changing the port to process.env.PORT
there should work anyway though.
If you want to see the codez, I put them on a Cloud9 project: webserver.