Home > Software design >  What is the proper way to use an array with res.header express node js
What is the proper way to use an array with res.header express node js

Time:10-16

I was using res.header to set the responce header in express JS. It looked like this.

let postHeader = [
  'Access-Control-Allow-Origin', 'http://localhost:3000',
  'Access-Control-Allow-Methods', 'POST',
  'Access-Control-Allow-Headers', 'X-Requested-With,content-type',
  'Access-Control-Allow-Credentials', 'true'
]
res.header(postHeader);
res.write(`{ "status" : "Wrong password." }`);
res.end();

Then I started getting "Type Error: res.header is not a function", but I only got it with one function, I changed res.write to res.send removing res.header and res.end and it fixed the problem. My question is am I using the array wrong? Thank You to anyone who responces.

CodePudding user response:

No every thing is right I tested this code on my pc and it work. May be there was some other issue.

  • Related