npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mongorestorm-server

v0.0.2

Published

A REST server for commonly used mongodb-driver operations.

Downloads

2

Readme

mongorestorm-server

NPM Build Status Coverage Status License

A REST Server abstraction of the commonly used [email protected] CRUD operations with schema definitions using @hapi/joi for data validations.

Getting Started

Installation

$ npm i mongorestorm-server

Usage

1. Import mongorestorm-server

const { MongoRestOrmServer } = require('mongorestorm-server');

2. Define MongoRestOrmServerConfig

const joi = require('@hapi/joi');

const config = {
  mongoConfig: {
    mongoUri: 'mongodb://127.0.0.1:27017/',
    dbName: 'test',
    clientOptions: {
      useNewUrlParser: true,
      useUnifiedTopology: true,
    },
    dbOptions: {},
  },
  corsConfig: {
    origin: '*',
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE',
    preflightContinue: false,
    optionsSuccessStatus: 204,
  },
  apiDocsConfig: {
    apiDocs: '/api-docs',
    swaggerUi: '/docs',
  },
  authConfig: null,
  logLevel: 'info',
  basePath: '/api',
  schemas: {
    userCollection: joi.object().keys({
      _id: joi.object().keys({
        $oid: joi.string().min(24).hex(),
      }),
      username: joi.string().required(),
      password: joi.string().required(),
    }),
  },
};

| MongoRestOrmServerConfig | Type | Description | Default | |------------------------------ |------- |------------ |--------------------------- | | mongoConfig | object | MongoDB Server connection configurations. | { mongoUri: 'mongodb://127.0.0.1:27017/', dbName: 'test', clientOptions: { useNewUrlParser: true, useUnifiedTopology: true } } | | mongoConfig.mongoUri | string | MongoDB Server connection string. | 'mongodb://127.0.0.1:27017/' | | mongoConfig.dbName | string | Database name. | 'test' | | mongoConfig.clientOptions | object | Please refer to: MongoClientOptions | { useNewUrlParser: true, useUnifiedTopology: true } | | mongoConfig.dbOptions | object | Please refer to: MongoClientCommonOption | {} | | corsConfig | object | Please refer to: CorsOptions | { origin: '*', methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', preflightContinue: false, optionsSuccessStatus: 204 } | | apiDocsConfig | string | MongoRestOrm Server uses the OpenAPI 3.0 specification to document and visualize it's API. Use null to turn off docs. | { apiDocs: '/api-docs', swaggerUi: '/docs' } | | apiDocsConfig.apiDocs | string | Path to access OpenAPI 3.0 specification JSON. | '/api-docs' | | apiDocsConfig.swaggerUi | string | Path to access OpenAPI 3.0 specification Swagger UI. | '/docs' | | authConfig | object | Configurations for built-in authentication. | null | | authConfig.secret | string | Secret to be used for validating Bearer token passed in the Authorization header. | 'secret' | | logLevel | string | Log level of the application. Log levels: info, warn, error, and debug. Use custom to turn off logging. | 'info' | | basePath | string | Prefix path of the MongoRestOrm Server enpoints. | '' | | schemas | string | Define database schema using @hapi/joi for data validation and visualization in docs. | {} |

3. Create MongoRestOrm Server instance

const mongoRestOrmServer = new MongoRestOrmServer(config);

4. Start MongoRestOrm Server

There are two ways of starting the MongoRestOrm Server.

Way 1

const port = 3000;
mongoRestOrmServer.startServer({ port });

Way 2

const express = require('express');
const app = express();
const port = 3000;

// Add custom middlewares here.

app.on('ready', () => {
  app.listen(port, () => {
    logger.info('Accepting connections at port: %d', port);
  });
});

mongoRestOrmServer.applyMiddleware(app);

Way 2 will allow adding of custom express middlewares such as own authentication middlewares.

Endpoints

All endpoints exposed by MongoRestOrm Server will be prefixed by the basePath that was provided in the MongoRestOrmConfig plus /dbs/ plus the mongoConfig.dbName. Example prefix: /basePath/dbs/dbName

To see the endpoints exposed by MongoRestOrm Server for the mongodb CRUD operations, please visit the Wiki.

MongoRestOrm Client

Comming Soon...

MongoDB Extended JSON

MongoRestOrm Server serializes and deserializes the data it receives and sends using the MongoDB Extended JSON (v2) specification to preserve special MongoDB types such as ObjectID.

Comparisons

| JSON | EJSON | BSON | |-------------------------------------- |------------------------------------------------ |------------------------------------------------ | | { _id: 'aaaaaaaaaaaaaaaaaaaaaaaa' } | { _id: { $oid: 'aaaaaaaaaaaaaaaaaaaaaaaa' } } | { _id: ObjectId('aaaaaaaaaaaaaaaaaaaaaaaa') } |

Packages that deserialize EJSON to a plain json/dict/struct with native/BSON types.

| Language | Package | |----------- |-------- | | Javascript | bson | | Python | pymongo | | Go | gomongo |

Recommendations

Usage of this package is only recommended for applications with a microservice architecture and should only have communications with other microservices within the application. Exposing the API to the client might cause some security issues.

Authors

  • Zishran Julbert Garces

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.