Bonnie Simon
Bonnie Simon

Reputation: 61

localhost:5000 is not loading my server!! Help needed

I am learning node and was creating a server using Traversy media video on node . Now before this I made a server using w3schools documentation and it worked . But us not working using Traversy Media's way.

The callback in the .listen is working but in browser it says 'Problem loading page'.

const http = require('http');

const server = http.createServer((req , res) => {
    console.log(req.url);
});

const PORT =5000;

server.listen(PORT , () => console.log(`server running at ${PORT}`));

browser keeps loading but never stops loading.

Upvotes: 0

Views: 1775

Answers (1)

Aritra Chakraborty
Aritra Chakraborty

Reputation: 12542

Please Read the documentation of how to create a server that will help you immensly.

const server = http.createServer((req , res) => {
    console.log(req.url);
});

In this case you are just printing the req.url without actually returning any response to the browser.

A proper hello world example will be:

http.createServer(function (req, res) {
  res.write('Hello World!'); //write a response to the client
  res.end(); //end the response
}).listen(8080);

Upvotes: 3

Related Questions