TypeError: convert circular structure to JSON in nodejs

I am using a query package for nodejs

I use this code here

var formData = ({first_name:firstname,last_name:lastname,user_name:username, email:email,password:password}); request.post({url:'http://localhost:8081/register', JSON: formData}, function(err, connection, body) { 

and

 exports.Register = function(req, res) { res.header("Access-Control-Allow-Origin", "*"); console.log("Request data " +JSON.stringify(req)); 

here I get this TypeError error : converting a circular structure to JSON

Can someone tell me what the problem is?

thanks

+5
source share
1 answer

JSON does not accept circular objects - objects that reference themselves. JSON.stringify() will JSON.stringify() error if it encounters one of them.

The request object ( req ) is circular in nature - Node does this.

In this case, since you just need to register it on the console, you can use the built-in console and avoid using JSON:

 console.log("Request data:"); console.log(req); 
+15
source

Source: https://habr.com/ru/post/1207567/


All Articles