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 pageres.end()
})
server.listen(8000);
Top comments (3)
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.
Hello Atul,
After changing the order of param. It's working fine. Thanks For Helping.
Youβre welcome :)