expressjs

expressjs

Express.js: the fast, unopinionated, minimalist web framework for node

Member Since 8 years ago

Experience Points
0
follower
Lessons Completed
0
follow
Best Reply Awards
41
repos
Activity
Oct
23
21 hours ago
started
started time in 1 hour ago
started
started time in 5 hours ago
Activity icon
issue

rofrol issue comment expressjs/express

rofrol
rofrol

TypeError: Converting circular structure to JSON

Im trying to send the request data, but I get an error message. Any idea on how I can fix this? (This error only occurs when I send JSON)

Here is my server.js:

const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");

const app = express();


app.use(cors());

const routes = { post: require("./routes/post") };
app.use("/post", routes.post);

const PORT = process.env.PORT || 8000;


app.listen(PORT, (err) => {
  if (err) console.log(err);
  else console.log(`Listening On Port ${PORT}`);
});

And here is my routes/post.js (where the main issue is I believe):

const router = require("express").Router();

router.post("/example", (req, res) => {
  res.json(req);
});

module.exports = router;

Edit: Here's the error message:

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>)
    at C:\Users\624234\Documents\ExpressTemplate\server\routes\post.js:4:17
    at Layer.handle [as handle_request] (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\route.js:137:13)
    at Route.dispatch (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\route.js:112:3)
    at Layer.handle [as handle_request] (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\layer.js:95:5)
    at C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\index.js:281:22
    at Function.process_params (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\index.js:335:12)
    at next (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\index.js:275:10)
    at Function.handle (C:\Users\624234\Documents\ExpressTemplate\node_modules\express\lib\router\index.js:174:3)
rofrol
rofrol

This worked for me:

https://stackoverflow.com/questions/11616630/how-can-i-print-a-circular-structure-in-a-json-like-format/21875464#21875464

I have just imported decycle function from https://github.com/douglascrockford/JSON-js/blob/master/cycle.js and then:

import { writeFileSync } from 'fs';
// ...
writeFileSync('res.json', JSON.stringify(decycle(res, undefined)));

instead of import you can use const fs = require('fs');;

Activity icon
fork

jason660519 forked expressjs/express

⚡ Fast, unopinionated, minimalist web framework for node.
jason660519 MIT License Updated
fork time in 9 hours ago
started
started time in 9 hours ago
started
started time in 10 hours ago
started
started time in 11 hours ago
started
started time in 12 hours ago
started
started time in 12 hours ago
started
started time in 12 hours ago
started
started time in 13 hours ago
Activity icon
fork

jxiansen forked expressjs/express

⚡ Fast, unopinionated, minimalist web framework for node.
jxiansen MIT License Updated
fork time in 14 hours ago
started
started time in 14 hours ago
started
started time in 14 hours ago
started
started time in 15 hours ago
started
started time in 16 hours ago
Activity icon
issue

saikarthikp9 issue expressjs/cookie-session

saikarthikp9
saikarthikp9

How to use cookie-session with React Native apps?

I am trying to use this package with a react native app but it is not working. Does anybody use this with their react native apps? I am specifically using Axios.

started
started time in 17 hours ago
started
started time in 20 hours ago
Oct
22
1 day ago
started
started time in 22 hours ago
started
started time in 1 day ago
started
started time in 1 day ago
Activity icon
fork

jgs110 forked expressjs/express

⚡ Fast, unopinionated, minimalist web framework for node.
jgs110 MIT License Updated
fork time in 1 day ago
started
started time in 1 day ago
started
started time in 1 day ago
started
started time in 1 day ago
started
started time in 1 day ago
started
started time in 1 day ago
Previous