Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Node JS Won't Print Hello World

Posted on 2015-02-20
8
Medium Priority
?
175 Views
Last Modified: 2015-02-22
I'm using node.js on a linux server. node js located at /usr/bin/node.  My helloworld.js  looks like this:

var http = require('http');

http.createServer(function (request, response) {
    response.writeHead(200, {'Content-Type': 'text/plain'});
    response.end('Hello World\n');
}).listen(8008);
;
console.log('Server started');

when executing  /usr/bin/node helloworld.js,  "Server started" prints in the console but what appears in the browser (servername.com:8008/helloworld.js) is the code block itself , not "Hello World" ???  I'm not able to find any info on this type of error.   Code worked just fine in wamp on my windows box.
0
Comment
Question by:kevbob650
  • 3
  • 3
  • 2
8 Comments
 
LVL 43

Expert Comment

by:Rob
ID: 40622543
you should be accessing: servername.com:8008 so drop the helloworld.js
0
 
LVL 43

Expert Comment

by:Rob
ID: 40622551
When you start your server you run: node helloworld.js
0
 

Author Comment

by:kevbob650
ID: 40624521
now I'm getting this error (or didn't see it the first time?):

$ node helloworld.js
Server started

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:904:11)
    at Server._listen2 (net.js:1042:14)
    at listen (net.js:1064:10)
    at Server.listen (net.js:1138:5)
    at Object.<anonymous> (/mypath/helloworld.js:6:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

I can't find documentation to understand the error message.   Thanks for first response!
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 25

Expert Comment

by:clockwatcher
ID: 40624535
That error means the port that you're trying to bind to is already in use.  Most likely because you have another instance of your helloworld.js node program still running.    Try a:

ps -Af | grep helloworld

To check.
0
 

Author Comment

by:kevbob650
ID: 40624550
Sorry, I'm a linux dummy, here's the results of that command, no idea what it means:
$ ps -Af | grep helloworld
13164 12422  0 19:55 pts/1    00:00:00 grep helloworld
0
 
LVL 25

Assisted Solution

by:clockwatcher
clockwatcher earned 1000 total points
ID: 40624568
From that output, it doesn't look like it's still running.   I would try starting it again and see if you still get that error.  

If you do, you can check what process is running on port 8008 with:

sudo netstat -anp | grep 8008

If you get any output from the above, the last column will tell you want process number is using the port.  E.g.,

mark@blue:~/node$ sudo netstat -anp | grep 8008
tcp        0      0 0.0.0.0:8008            0.0.0.0:*               LISTEN      9124/node

The above indicates that process 9124 (node) is running listening on port 8008.
0
 

Author Comment

by:kevbob650
ID: 40624595
looks like it's now:   tcp        0      0 1XX.XX.XX.XX:8008          0.0.0.0:*                   LISTEN      -
0
 
LVL 43

Accepted Solution

by:
Rob earned 1000 total points
ID: 40624608
So for testing just ruin your node app on another port, like 8009
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Suggested Courses
Course of the Month11 days, 2 hours left to enroll

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question