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:
I'm fairly certain my code is right, is there anything else I'm doing wrong?
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()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With