0

i am trying to setup a web server using nodejs. The following code below is directly from the nodejs.org website just configured with my server credentials.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World\n');
}).listen(5000, '10.0.1.51');
console.log('Server running at http://10.0.1.51:5000/');

but when i go to 10.0.1.51:5000 nothing is found i don't even get an error in my console.

also the book i am learning from provided me with this

var connect = require('connect');
connect.createServer(
    connect.static("../angularjs")
).listen(5000);

and that still doesn't work. I'm not sure on where to look to resolve this issue, thanks.

hello world
  • 1,431
  • 3
  • 17
  • 33
  • The last code snippet is outdated, fyi. The first one appears fine.. Are you positive the server is running? I recommend you put your `console.log` in the callback of `listen`. `listen(5000, '10.0.1.51', function() { console.log(etc); });` – m59 Feb 19 '15 at 03:38
  • @m59 im testing node with a basic function like this function testNode() {return "Node is working"}; testNode(); but I'm not sure if this is the proper way to test node if its running or not. – hello world Feb 19 '15 at 03:40
  • 1
    Is `10.0.1.51` the actual IP address of your server? What happens if you do `ping 10.0.1.51`? – jfriend00 Feb 19 '15 at 03:41
  • @jfriend00 yes, here are my logs. PING 10.0.1.51 (10.0.1.51) 56(84) bytes of data. 64 bytes from 10.0.1.51: icmp_seq=1 ttl=64 time=0.016 ms – hello world Feb 19 '15 at 03:42
  • What I'm saying is that you should be starting the server with `node your-server-file` and if you put your log in the callback of `listen`, you'll know for sure it has started up successfully. Since you are new to node, I also want to be sure you are typing that in the command line and watching the command line for the log to appear. – m59 Feb 19 '15 at 03:42
  • @m59 so when i enter node server.js in the REPL shell three dots appear and nothing else, I'm assuming this isn't normal from what your comment is saying. – hello world Feb 19 '15 at 03:47
  • http://stackoverflow.com/questions/20756568/node-example-js-and-three-dots-whats-next – m59 Feb 19 '15 at 03:51
  • @m59 ill look into that and i didn't see the rest of of your 1st comment. thanks tho!!! – hello world Feb 19 '15 at 03:55

0 Answers0