json-server
json-server copied to clipboard
How to watch db.json when using the project as a 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.
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.
the standard file loading mechanism
What is the standard file loading mechanism, please? CLI mode?