0

I wanted node js to listen to a port, so i used the below code

var http = require('http');
http.createServer(function (req, res) {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('Hello World\n');
}).listen(3000, "127.0.0.1");

Regardless of what i use in .listen its listening to port number 1337

Vignesh Subramanian
  • 7,161
  • 14
  • 87
  • 150
  • downvoters, care to drop a comment on what should be improved – Vignesh Subramanian Aug 17 '15 at 06:21
  • 1
    Sounds like a stupid question but have you restarted your server after making changes? :) – AdityaParab Aug 17 '15 at 06:54
  • yes i did and I am a beginner to node js and i am facing this issue if its so simple, i think they should provide a solution instead of downvoting :) because, i have explained the problem with my code clearly and this question is not a duplicate of any other question either. beginners might face the same issue again in future :) – Vignesh Subramanian Aug 17 '15 at 07:02
  • Okay, I upvoted. (no idea who and why downvoted it.) The code looks fine to me. I don't think there is any issue with your code. Please make sure you're runnint the right code. Sometimes, out of panic, we miss out on obvious things. :) – AdityaParab Aug 17 '15 at 07:07
  • Thanks :) yeah, I think I am misplacing these lines in the app.js file – Vignesh Subramanian Aug 17 '15 at 07:09
  • 1
    As a second thought, since you've provided `hostname` parameter, try changing your listen statement to `.listen(3000, "127.0.0.1",null,null);` or to just `.listen(3000);` – AdityaParab Aug 17 '15 at 07:11
  • 1
    Please don't drastically change your questions otherwise other people who have the same issue you do will be confused by the answers below that reference things no longer in your current version of the question. – slebetman Aug 17 '15 at 07:28

0 Answers0