Skip to content

Instantly share code, notes, and snippets.

@crobinson42
Created September 15, 2016 20:22
Show Gist options
  • Select an option

  • Save crobinson42/217f619e5d5f9133b700ecc04533eb12 to your computer and use it in GitHub Desktop.

Select an option

Save crobinson42/217f619e5d5f9133b700ecc04533eb12 to your computer and use it in GitHub Desktop.
js-data-express schema validation
const express = require('express')
const app = express()
const jsData = require('js-data')
const jsDataExpress = require('js-data-express')
const store = new jsData.Container()
const MongoDBAdapter = require('js-data-mongodb')
const adapter = new MongoDBAdapter.MongoDBAdapter({debug: false, uri:'mongodb://localhost:27017/my-dev-db'})
store.registerAdapter('mongodb', adapter, { default: true })
const userMapper = store.defineMapper('user', {
schema: {
type: 'object',
properties: {
id: { type: 'number' },
name: { type: 'string' }
}
}
})
app.use('/user', new jsDataExpress.Router(userMapper).router)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment