2

I'm not sure if this is possible, but I would like to see the whole content of the req object in client side.

const express = require('express');

const app = express();

app.get('/', (req, res) => {
    // send req object to the client
    res.json(req);
});

app.listen(5000, () => {
    console.log('Server successfully started on port 5000');
});

This will result in an error like:

TypeError: Converting circular structure to JSON

Andrei Rosu
  • 1,169
  • 2
  • 10
  • 26

2 Answers2

1

The req object contains a lot of data. I don't think that you need all of theses to be sent back to client side.

You should select what you want to send back, and be sure theses values are not posing a ciruclar issue.


Like :

res.json({
  body: req.body,
});
Orelsanpls
  • 22,456
  • 6
  • 42
  • 69
  • Thank you for the answer. I just prefer that as a method of debugging instead of other methods because it's easier for me to see the whole object in client side. – Andrei Rosu Aug 31 '18 at 09:27
0

Sends a JSON response composed of a stringified version of the specified data. usage:

return res.json([statusCode, ] data);

Example:

var info = [
{id:1, name: "test 1"},
{id:2, name: "test 2"}
]
const express = require('express');
const app = express();
app.get('/', (req, res) => {
// send req object to the client
res.json(info);
});
app.listen(5000, () => {
console.log('Server successfully started on port 5000');
});

or i think that it's better to use body-parser