Anagh Basak
Anagh Basak

Reputation: 147

Node server is not starting

const http = require('http');

const server = http.createServer((res, req) => {
    res.write("Welcome to our home page");
    res.end();

})

server.listen(5000);

I compiled the code using node filename.js. However it is showing res.write()is not a function. At times the error is not showing until I try to access the localhost.

Upvotes: 0

Views: 84

Answers (1)

moonwave99
moonwave99

Reputation: 22817

You flipped the parameters - req (request) goes first:

const server = http.createServer((req, res) => {
    res.write("Welcome to our home page");
    res.end();
});

Upvotes: 5

Related Questions