Search code examples
javascriptnode.jsweb

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?


Solution

  • 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().