DEV Community

Discussion on: How to easily create and host your own REST API without writing a single line of code

Collapse
 
amlana24 profile image
amlan

Is there a way to add auth to it?

Collapse
 
myogeshchavan97 profile image
Yogesh Chavan

yes, you can add authentication using middleware like this:

// 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')
})
Enter fullscreen mode Exit fullscreen mode