I'm trying to set up a simple web server that returns the contents of the request as a response with node.js and express.js. My code is as below:
const express = require('express');
const app = express();
const port = 3000;
app.get("/", function(request,response){
// console.log(request);
response.send(request);
});
app.listen(port, function() {
console.log("Server started on port #" + port);
});
And I get this error:
TypeError: Converting circular structure to JSON
--> starting at object with constructor 'Socket'
| property 'parser' -> object with constructor 'HTTPParser'
--- property 'socket' closes the circle
at JSON.stringify (<anonymous>)
What exactly is happening and how can I modify my code to achieve my initial goal? I want to return a response that contains the contents of the request. I can console.log(request)
without any issues so I'm even more confused here.
I tried looking up this error but most don't seem to apply to this case.