typicode / json-server

Get a full fake REST API with zero coding in less than 30 seconds (seriously)
Other
72.83k stars 7.02k forks source link

template in db.json #880

Open zoutepopcorn opened 5 years ago

zoutepopcorn commented 5 years ago

I'm running JSON server from my nodejs process.

It's real simple, but for my program I want a default template. I did not find it, so I use:

const jsonServer = require('json-server')
const server = jsonServer.create()
const fs = require('fs');
if (!fs.existsSync('db.json')) {
    fs.writeFileSync('db.json', JSON.stringify({
        "couters": [{
            "persons": 0
        }],
        "persons": []
    }));
}

const router = jsonServer.router('./db.json')
const express = require('express');
const middlewares = jsonServer.defaults()
....

I realy would like to like

const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('./db.json',{
                    "couters": [{
                        "persons": 0
                    }],
                    "persons": []
                })
...

Is this possible?

northkode commented 5 years ago

https://github.com/dfsq/json-server-init