Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node server.js not responding

I'm pretty new to node and I'm trying to create a simple server for my website but when I type in node server.js in command prompt nothing happens.

var http = require("http");  
http.createServer(function(request, response) {
       response.writeHead(200, {"Content-Type": "text/plain"});
       response.write("It's alive!");
       response.end();
}).listen(3000);

This is what I see when I try to run my server.js file:

enter image description here

I'm fairly certain my code is right, is there anything else I'm doing wrong?

like image 347
Daniel Huang Avatar asked Jul 24 '15 16:07

Daniel Huang


1 Answers

The server is working just fine. You need to visit http://localhost:3000/ from your browser to view the expected output ("It's alive!").

To write messages to the console, use console.log().

like image 142
galactocalypse Avatar answered Oct 13 '22 01:10

galactocalypse