``````
'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 !
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.
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.