-1

this is my code along with the error

This was supposed to make a server on the specified port. The error is Nodemon app crashed waiting for file changes before starting.I have tried changing ports it is not helping and there is no server running in the background.

1 Answers1

1

You can not pass an argument to server.listen as a string

const http = require('http');
const PORT=2000;
const HOST="localhost";

const server = http.createServer((req, res, next) => {
    if(req.url == "/about"){
        return res.end("<h1> About page</h1>")
    }
})

server.listen(PORT, HOST,()=>{
    console.log(`server is running on http://${HOST}:${PORT}`)
})
Mohammad Yaser Ahmadi
  • 4,664
  • 3
  • 17
  • 39