James
James

Reputation: 1945

getting server forbidden error in my browser

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

Upvotes: 4

Views: 15056

Answers (2)

mido
mido

Reputation: 25054

probably like my current PC, yours too must be running McAfee or some other program is already using port 8081, you got two options:

  • stop McAfee or the other program running on that port
  • listen to a different port on your node server

Upvotes: 16

Nayan Patel
Nayan Patel

Reputation: 1759

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.

Upvotes: 1

Related Questions