- Notifications
You must be signed in to change notification settings - Fork6
Plugin to share a common GunDB connection across Fastify 🔫
License
NotificationsYou must be signed in to change notification settings
lmangani/fastify-gundb
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
FastifyGunDB connection plugin, with this you can share a Gun instance in every part of your server.
npm i fastify-gundb --save
Add it to you project withregister
and you are done!
You can access Gun viafastify.gun
.
constfastify=require('fastify')fastify.register(require('fastify-gundb'),{name:'db'},err=>{if(err)throwerr})fastify.get('/foo',(req,reply)=>{const{ gun}=fastify.gungun.get(req.query.key).once(function(val){if(!val)val={status:404}reply.send(val)})})fastify.post('/foo',(req,reply)=>{const{ gun}=fastify.gungun.get(req.body.key).put(req.body.value,(ack)=>{if(!ack)val={status:'error'}reply.send({status:'ok'})})})fastify.listen(3000,err=>{if(err)throwerrconsole.log(`server listening on${fastify.server.address().port}`)})
This project is kindly sponsored by:
Fastify is kindly sponsored by:
Licensed underMIT.