Hello, all. I am missing a subtle nuance in this tutorial and come to you pleading for direction.
The tutorial gives this code:
// Require what we need
var http = require(“http”);
// Build the server
var app = http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.end("Hello world!\n");
});
// Start that server, baby
app.listen(1337, "localhost");
console.log("Server running at http://localhost:1337/");
then goes on to say:
"…if you run that app (if that file is called app.js, you’d run node app.js), you’ll get a response of “Hello world!” if you visit localhost:1337 in your browser. "
If you’re on c9, you can only use ports 8080, 8081 and 8082. You can’t just use localhost to see the running app. It goes something like https://<workspace name>-<account name>.c9users.io (there should be a Preview button in c9. Click that, then click View Running Application (or something similar))
your code works fine i copied it pasted it into notepad saved it as app.js put it in a folder i created and then ran it using node.js … and it will run on localhost:1337 … if you have node installed on your computer you can also do this … just cd to folder then type node app … but if you are new to this i understand why you are confused … as previous person stated about ports to be used on c9 … i havent used c9 yet so i cant say … you could try changing app.listen(1337, “localhost”); to
app.listen(8080, “localhost”); should work.
"Cloud9 can’t get you to your requested workspace. Here are some suggestions on how to figure out what’s going on:
Check that the workspace name (learnnode) and username (olddognewtrix123) are typed correctly." — CHECKS OUT
"Check that the server is successfully running on Cloud9:" I MEAN, “Server running at http://localhost:8080/” — SO, IT’S RUNNING
"If the server hit an error, the output window will have a message telling you what it is" — NO ERRORS REPORTED
"If you’re in the middle of debugging code, your server might be paused right now" — NOT RUNNING DEBUG MODE
"The server might be running on a different port; make sure it’s on port $PORT with $IP as the IP address" — I AM RUNNING “app.listen(8082, “localhost”);” already (I TRIED 8080, 8081, and now 8082)
So, not sure where to go from here. Still not seeing “Hello World!”
In your app.listen(), try removing the 'localhost' string. Just pass 8080.
I tried your code in my instance of c9, but without that 'localhost'. I still got the little error toast in the terminal, but I could see the running app.
var http = require("http");
var port = process.env.PORT; // added this
var app = http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.end("Hello world!\n");
});
//app.listen(8082, "localhost"); --- commented this out
app.listen(port); // added this
console.log("Server running at http://localhost:8082/");
Got server running, then clicked Tools → Preview → Preview Running Application