Nautilus: Pelagic Mollusc

    fastify-pouchdb
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.3 • Public • Published

    fastify-pouchdb

    npm Downloads TypeScript GitHub license

    Fastify plugin to use PouchDB

    Install

    npm install fastify-pouchdb --save
    npm install @types/pouchdb --save-dev

    Usage

    import * as fastify from 'fastify';
    import fastifyPouchDB from 'fastify-pouchdb';
     
    const server: fastify.FastifyInstance<Server, IncomingMessage, ServerResponse> = fastify({
      logger: true,
    });
     
    server.register(fastifyPouchDB, {
      name: 'myleveldb',
    });
     
    server.get('/', async (request, reply) => {
      try {
        const result = await server.pouchdb.allDocs();
        return {
          error: 0,
          data: result,
        };
      } catch (e) {
        return {
          error: 1,
          msg: e.message,
        };
      }
    });
     
    server.get('/put', async (request, reply) => {
      try {
        const result = await server.pouchdb.put({
          _id: 'mydoc',
          title: 'Heroes',
        });
        return {
          error: 0,
          data: result,
        };
      } catch (e) {
        return {
          error: 1,
          msg: e.message,
        };
      }
    });
     
    server.listen(3000, (err, address) => {
      if (err) {
        server.log.error(err);
        process.exit(1);
      }
      server.log.info(`server listening on ${address}`);
    });
     

    Keywords

    Install

    npm i fastify-pouchdb

    DownloadsWeekly Downloads

    1

    Version

    1.0.3

    License

    MIT

    Unpacked Size

    181 kB

    Total Files

    13

    Last publish

    Collaborators

    • -kain