How to set defaults options as module?
var jsonServer = require('json-server')
var server = jsonServer.create()
var router = jsonServer.router('db.json')
var middlewares = jsonServer.defaults()
server.use(middlewares)
I try to set static directory,it did not work. :(
var middlewares = jsonServer.defaults({static:'./app'})
@PhoonLee were you able to figure out how to log the static files?.
I wanted to use something like this var jsonServer = require('json-server') var server = jsonServer.create() var router = jsonServer.router('db.json') var middlewares = jsonServer.defaults({quiet: true}); server.use(middlewares)
it is also not working, I want to stop logs on the output window
Sorry for 4 years late response :)
Based on the documentation:
The path you provide to the jsonServer.router function is relative to the directory from where you launch your node process. If you run the above code from another directory, it’s better to use an absolute path:
const path = require('path')
const router = jsonServer.router(path.join(__dirname, 'db.json'))
so try:
const path = require('path');
const router = jsonServer.defaults({
static: path.join(__dirname, './app')
});