DEV Community

Cover image for Facing Error res.setHeader not a Function
Shailesh Waghole
Shailesh Waghole

Posted on

Facing Error res.setHeader not a Function

I have to write code to create a node.js server. But after using the res.setHeader method. I am getting an error that res.setHeader is not a function.
Following is my Code:


const http=require('http');

const server=http.createServer((res,req)=>{
res.setHeader('Content-Type','text/html')
res.write('

Hello This is response from NodeJS>Server

')//this method is used to display the response on the web page
res.end()

})

server.listen(8000);


Top comments (3)

Collapse
 
atuls1396 profile image
Atul Singh

The callback function should be (req,res). The ordering of the arguments matter.
Try the same after changing the order of the arguments because the rest of it looks good to me.

Collapse
 
shailesh6363 profile image
Shailesh Waghole

Hello Atul,
After changing the order of param. It's working fine. Thanks For Helping.

Collapse
 
atuls1396 profile image
Atul Singh

You’re welcome :)