DEV Community

Discussion on: NodeJs Response

Collapse
 
dasrajanraj profile image
Rajan Raj Das

Dhanush, you can add it in the header of the response or in the body of the response(classical way)

  1. To add in the header
    res.setHeader("abc", "Finding out")

  2. To add in the body
    res.status(200).json({result : "Message Successful", abc : "Finding Out"})

Collapse
 
dhanushnehru profile image
Dhanush N

Hey Rajan,
Thanks for your input

I know that we can add it by setting header, but my question is if we don't add it in header & only assign the value can it be got from frontend.

Collapse
 
dasrajanraj profile image
Rajan Raj Das • Edited

No, you cannot do that. If you see the basic of Http response packet. It has header section( with several sub heading ) and a response body. These are the protocol that guide the communication between client and server.
If you are directly adding a field ( i.e. abc ) in the response , it cannot create its own section apart from what is defined in the protocol ,right?
I think this would answer you question.