Home

Awesome

feathers-lowdb

NPM version Downloads Test Runner

feathers-lowdb is a FeathersJS database adapter for Lowdb, a small JSON and YAML database for Node, and the browser. LowDB can store data in-memory or on the filesystem which makes it useful as a persistent storage without a separate database server.

$ npm i feathers-lowdb

Try it Online

Advanced

LowDB benefits over NeDB, SQLite and others

API

yaml([options])

Returns a new database instance initialized with the given options.

import { LowDBService } from 'feathers-lowdb'

export const createModel = (app: Application) => {
  return new LowDBService({
    filename: 'users.yaml', // or users.json
    id: '_id', // todo: https://github.com/feathersjs/feathers/issues/2839
    startId: 1,
    paginate: {
      default: 2,
      max: 4
    }
  })
}

Options:

Example

Here is an example of a Feathers server with a messages LowDB service that supports pagination and persists to messages.yaml:

$ npm i @feathersjs/feathers @feathersjs/koa @feathersjs/socketio feathers-lowdb@alpha

In app.js:

import { feathers } from '@feathersjs/feathers'
import {
  koa,
  rest,
  bodyParser,
  errorHandler,
  serveStatic,
} from '@feathersjs/koa'
import socketio from '@feathersjs/socketio'
import { LowDBService } from 'feathers-lowdb'

// Creates an ExpressJS compatible Feathers application
const app = koa(feathers())

// Use the current folder for static file hosting
app.use(serveStatic('.'))
// Register the error handle
app.use(errorHandler())
// Parse JSON request bodies
app.use(bodyParser())

// Register REST service handler
app.configure(rest())
// Configure Socket.io real-time APIs
app.configure(socketio())
// Register our messages service
app.use(
  '/messages',
  new LowDBService({
    filename: 'messages.yaml', // or messages.json
    id: '_id', // todo: https://github.com/feathersjs/feathers/issues/2839
    startId: 1,
    paginate: {
      default: 2,
      max: 4
    }
  })
);

// Create a dummy Message
app
  .service('messages')
  .create({
    text: 'Message created on server',
  })
  .then((message) => console.log('Created message', message))


app.listen(3030, () => {
  console.log(`Feathers server listening`)
})

Run the example with node app and go to localhost:3030/messages.

Try this example online: https://stackblitz.com/fork/lowdb-qs-first-app

License

Copyright (c) 2023

Licensed under the MIT license.