You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
647 B
30 lines
647 B
const fastifyPlugin = require('fastify-plugin')
|
|
|
|
/**
|
|
* adding lowdb to fastify
|
|
*
|
|
* @author Björn Hase, Tentakelfabrik
|
|
* @license http://opensource.org/licenses/MIT The MIT License
|
|
* @link https://github.com/tentakelfabrik/fastify-lowdb-riotjs-lessons-learned
|
|
*
|
|
*/
|
|
|
|
module.exports = fastifyPlugin((fastify, opts, done) => {
|
|
|
|
const fileDB = './storage/db.json'
|
|
|
|
const low = require('lowdb')
|
|
const FileSync = require('lowdb/adapters/FileSync')
|
|
|
|
const adapter = new FileSync(fileDB)
|
|
const db = low(adapter)
|
|
|
|
db.defaults({
|
|
notes: []
|
|
}).write()
|
|
|
|
// adding
|
|
fastify.decorate('db', db)
|
|
done()
|
|
|
|
}) |