json-server icon indicating copy to clipboard operation
json-server copied to clipboard

How to watch db.json when using the project as a module

Open MO-miro opened this issue 3 years ago • 1 comments

doc of module

$ node server.js
// server.js
const jsonServer = require('json-server')
const server = jsonServer.create()
const router = jsonServer.router('db.json')
const middlewares = jsonServer.defaults()

server.use(middlewares)
server.use(router)
server.listen(3000, () => {
  console.log('JSON Server is running')
})

I use json-server like this, but node won't restart when db.json file changed.

MO-miro avatar Mar 15 '22 11:03 MO-miro

cant do it and dont even try. Using this way, the db.json is loaded once and the src file is never watched when loaded in that fashion.

Switch back to using the standard file loading mechanism and you'll get the auto-reload on change for free.

ericnewton76 avatar May 12 '22 14:05 ericnewton76

the standard file loading mechanism

What is the standard file loading mechanism, please? CLI mode?

microkof avatar Nov 08 '22 06:11 microkof