express-restify-nedb-simple
v1.1.1
Published
Easily create a simple express REST interface for nedb models
Downloads
4
Maintainers
Readme
express-restify-nedb-simple
Easily create a simple express REST interface for nedb models.
Getting started
npm install express-restify-nedb-simple --save
Usage
This snippet…
const app = express()
const router = express.Router()
const usersModel = new Datastore('path/to/users.db')
app.use(bodyParser.json())
restify.serve(router, usersModel)
app.use('/api', router)
…automatically generates these endpoints:
GET http://localhost/api/users/count
GET http://localhost/api/users
POST http://localhost/api/users
GET http://localhost/api/users/:id
PUT http://localhost/api/users/:id
DELETE http://localhost/api/users/:id
the default response is a JSON:
{
"ok": true,
"data": {}
}
You can add a custom response by adding a third parametter:
restify.serve(router, usersModel, (data) => {myResponse: data})
Case errors, will pass by the error with
next()