Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getting server forbidden error in my browser

Tags:

node.js

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

like image 596
James Avatar asked Dec 02 '22 14:12

James


2 Answers

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:

  • stop McAfee or the other program running on that port
  • listen to a different port on your node server
like image 118
mido Avatar answered Dec 25 '22 12:12

mido


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.

like image 26
Nayan Patel Avatar answered Dec 25 '22 13:12

Nayan Patel