Not able to set database id?
hernebrink opened this issue · 3 comments
hernebrink commented
I'm not sure if this is a feature request or an issue...
I've been trying to figure out how to set the database id, which you can do in an npm script like this:
"scripts": {
"differentId": "json-server db.json --id name"
}
The only thing I could think of was to pass the following options in server.js:
const router = jsonServer.router('db.json', { foreignKeySuffix: 'name' });
But that did not do the trick.
Is there a way to do this?
jesperorb commented
Maybe this?
typicode/json-server#279 (comment)
hernebrink commented
Thanks, Jesper! That was exactly what I was trying to achieve! :)
hernebrink commented
Was able to set the router._id field directly:
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
router.db._.id = "name";
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3000;