DEV Community

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

Posted on

1

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 :)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay