Json-server: TypeError: Cyclic __proto__ value

Created on 18 Jan 2016  路  3Comments  路  Source: typicode/json-server

``````
'use strict'

var jsonServer = require('json-server');

// Returns an Express server
var server = jsonServer.create();

// Set default middlewares (logger, static, cors and no-cache)
server.use(jsonServer.defaults());

// Add custom routes
var router = server.get('/custom', function (req, res) { res.json({ msg: 'hello' }) });

//var router = jsonServer.router('db.json');

//server.use(router);

server.listen(8001);```
``````

Using your basic example, i get this error:

/home/sami/Desktop/e2eupload/node_modules/json-   server/node_modules/express/lib/application.js:97
this.request.__proto__ = parent.request;
                       ^

TypeError: Cyclic __proto__ value
at IncomingMessage.set __proto__ (native)
at EventEmitter.onmount (/home/sami/Desktop/e2eupload/node_modules/json-  server/node_modules/express/lib/application.js:97:28)
at emitOne (events.js:77:13)
at EventEmitter.emit (events.js:169:7)
at EventEmitter.<anonymous> (/home/sami/Desktop/e2eupload/node_modules/json-server/node_modules/express/lib/application.js:237:8)
at Array.forEach (native)
at EventEmitter.use (/home/sami/Desktop/e2eupload/node_modules/json-server/node_modules/express/lib/application.js:216:7)
at Object.<anonymous> (/home/sami/Desktop/e2eupload/test.js:20:8)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)

Maybe I did something wrong ? Thanks for helping me !

Most helpful comment

I don't know if can help, but this error generally happens when you set a middleware to the app (server in your case) that is the app itself.

app.use(app);

All 3 comments

Using your code I can't reproduce but I've noticed that if server.use(router) is uncommented I'm getting the same error.

If you just write:

server.get('/custom', function (req, res) { res.json({ msg: 'hello' }) });

instead of:

var router = server.get('/custom', function (req, res) { res.json({ msg: 'hello' }) });

It should work better :)

I don't know if can help, but this error generally happens when you set a middleware to the app (server in your case) that is the app itself.

app.use(app);

Thank you for the information @Splact
I think this issue can be closed.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dotmobo picture dotmobo  路  4Comments

Rutvik17 picture Rutvik17  路  4Comments

bahmutov picture bahmutov  路  3Comments

boydenhartog picture boydenhartog  路  3Comments

Isanderthul picture Isanderthul  路  3Comments