can't watch multiple files with json-server can't watch multiple files with json-server json json

can't watch multiple files with json-server


create files as shown below

db.js

var firstRoute  = require('./jsonfile1.json');var secondRoute = require('./jsonfile2.json');var thirdRoute  = require('./jsonfile3.json');var fourthRoute = require('./jsonfile4.json');// and so onmodule.exports = function() {return {firstRoute  : firstRoute,secondRoute : secondRoute,thirdRoute  : thirdRoute,fourthRoute : fourthRoute// and so on }}

server.js

var jsonServer  = require('json-server')var server      = jsonServer.create()var router      = jsonServer.router(require('./db.js')())var middlewares = jsonServer.defaults()server.use(middlewares)server.use(router)server.listen(3000, function () {console.log('JSON Server is running')})

Now go to the directory where you have created both these files and open command line and run the code below

node server.js

That's it now go to the browser and go to localhost:3000 ,You shall see the routes that created for different files,you may use it directly.


You can open multipe port for differents json files with json-server.In my caseI open multiples cmd windows and launch it as.

json-server --watch one.json -p 4000

json-server --watch two.json -p 5000

json-server --watch more.json -p 6000

One for cmd window, this work for me.


It can only watch one file. You have to put the all info you need into the same file. So if you need cars for one call and clients for another, you would add a few objects from each into one file. It's unfortunate, but it's just supposed to be a very simple server.