简体   繁体   中英

How to send request parameter from Express server to React application?

I want to send these request headers to my react application:

app.get('/',function(req, res, next){

      req.user = req.headers["id"];
      next(null, req.user);

}) 

To send anything to client you need to put it in res , rather than req .

Do res.user = req.headers["id"]; instead of req.user = req.headers["id"];

Edit

next() is used to pass the response to next middleware function. If you want to send response back to client then you should use, res.send or res.json .

Like, res.json({"userid": XYZ})

Read More

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM