I have just started exploring node.js. Have installed msi file on my windows server. My code below returns me expected output in command window
var http = require("http");
http.createServer(function (request, response) {
// Send the HTTP header
// HTTP Status: 200 : OK
// Content Type: text/plain
response.writeHead(200, {'Content-Type': 'text/plain'});
// Send the response body as "Hello World"
response.end('Hello World\n');
}).listen(8081);
// Console will print the message
console.log('Server running at `http://127.0.0.1:8081/`');
But when i type http://127.0.0.1:8081/
in my browser i dont get any output. When i see console i get below error
Failed to load resource: the server responded with a status of 403 (Forbidden)
What i wrong and how to fix? I am following this link
probably like my current PC, your's too must be running McAfee or some other program is already using port 8081, you got two options:
var http = require("http");
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/plain'});
response.end('Hello World\n');
}).listen(300);
console.log('Server running at http://127.0.0.1:300/');
I changed it to 300 from 8081 and it worked.
http://127.0.0.1:300/ this url gives the desired output.
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