This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including feathers-nedb-fuzzy-search
with all npm
packages installed. Try it out:
const feathers = require('feathers')
const hooks = require('feathers-hooks')
const NeDB = require('nedb')
const service = require('feathers-nedb')
const search = require('feathers-nedb-fuzzy-search')
const Model = new NeDB({
filename: './example.db',
autoload: true
})
const app = feathers()
app.configure(hooks())
app.use('/test', service({ Model }))
app.hooks({
before: { find: search() }
})
// you need node v7 or above for async / await syntax
async function testDatabase () {
let service = app.service('test')
await service.create([
{ 'title': 'asdf' },
{ 'title': 'qwerty' },
{ 'title': 'zxcvb' },
{ 'title': 'hello world' },
{ 'title': 'world around' },
{ 'title': 'cats are awesome' },
])
let res = await service.find({ query: { $search: 'world' } })
console.log(res)
// [ { title: 'world around', _id: '1RDM5BJWX4DWr1Jg' },
// { title: 'hello world', _id: 'dX4bpdM1IsAFkAZd' } ]
}
testDatabase()
.catch(e => console.error(e))
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.