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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@goodly/mongoframework

v0.0.7

Published

This API is designed to help companies identify the right people to contact at the right time to reduce the cost of unsuccessful product pitching

Readme

Mongo Express RESTful JSON API

This is basic mongo express framework that uses a configuration file
to expose CRUD operations via a RESTful JSON API.

Quick Start

Install

npm i @goodly/mongoframework

Configure the API

Create a config.js file in the root directory of the project and
add the code bellow.

module.exports = {
    database: {
        host: process.env.DB_HOST || '0.0.0.0',
        port: process.env.DB_PORT || '27017',
        name: process.env.DB_DATABASE || 'phonebook',
        user: process.env.DB_USER || 'root',
        password: process.env.DB_PASSWORD || 'password'
    },
    api: {
        baseURL: '/api/v1',
        port: process.env.API_PORT || '3000',
        maxResponseSize: 50,
        filters: {
            pageNo: 'pageNo',
            pageSize: 'pageSize',
            sortBy: 'sortBy',
            order: 'order'
        }
    },
    endpoints: {
        people: {
            schema: {
                table: 'people',
                isEmbedded: false,
                fields: {
                    name: {
                        type: 'string',
                        required: true
                    },
                    surname: {
                        type: 'string',
                        required: true
                    },
                    mobilenumber: {
                        type: 'mobile',
                        required: true
                    },
                    emailaddress: {
                        type: 'email',
                        required: true
                    }
                }
            },
            http: {
                get: ['', '/:id'],
                post: [''],
                patch: ['/:id'],
                delete: ['/:id']
            }
        }
    }
}

Create index.js

Crate a index.js file and copy and paste the code bellow
to expose the api on the desired port.

const app = require('@goodly/mongoframework').app
const config  = require('@goodly/mongoframework').config
const http = require('http')


const port = Number.parseInt(config.api.port)
app.set('port', port)

const server = http.createServer(app)

const listen = () => {
  console.log('Listening on port: '.concat(port))
}

server.on('listening', listen)
server.listen(port)

Run API

To run the api simply run the code bellow in the terminal

node index

Detailed guide

Configuration process

All configuration is done in the config.js file. Create the file in
the root directory of your project. The file shoudl contain, database,
api and endpoint configuration. Paste the code bellow inside the your
config.js file and paste all other configs inside it.

Entry point code

modules.exports = {

}

Database connectivity

Change the default values as required.

database: {
    host: process.env.DB_HOST || '0.0.0.0',
    port: process.env.DB_PORT || '27017',
    name: process.env.DB_DATABASE || 'petstore',
    user: process.env.DB_USER || 'root',
    password: process.env.DB_PASSWORD || 'password'
}

HTTP Server API configuration

Change the default values as required

api: {
    baseURL: '/api/v1',
    port: process.env.API_PORT || '3000',
    filters: {
      pageNo: 'pageNo',
      pageSize: 'pageSize',
      sortBy: 'sortBy',
      order: 'order'
    }
}
 

API Endpoint configuration

The endpoints property is used to describe the database tables and http
endpoints that expose the database via REST API. Endpoints has two
main properties shcema and http

endpoints: {
    schema: {

    },
    http: {

    }
}

schema

The schema property is used to describe how each table (collection) will
store data.

schema: {
    table: 'people',
    isEmbedded: false,
    fields: {
        name: {
            type: 'string',
            required: true
        },
        surname: {
            type: 'string',
            required: true
        },
        mobilenumber: {
            type: 'mobile',
            required: true
        },
        emailaddress: {
            type: 'email',
            required: true
        }
    }
}

Table

The table property is used to define the table (collection) name.

isEmbedded

The isEmbedded property is used to define if a document is embedded in another.
If it is an embedded document use the table (collection) name of the parent document.

Fields

The fields property is used to define all the document properties and thier respective
types and if its required. Supported types are listed bellow.

|type | Description | Supporting tags | |--------------|--------------------------------------|------------------| | string | all strings including an empty String| | | mobile | phone numbers | | | email | email address | | | alpha | alphabet values only (a-z) | | | alphanumeric | alphabets and numbers (a-z) and (0-9)| | | date | javascript date values | | | int | integers | | | numeric | integers, doubles, floats | | | boolean | boolean values true and false | | | enum | one of a list of predefined value | list: [array] | | custom | support for regex based validation | regex: Regex |

http

The http property is used to define the available http methods and paths
relating to an entitiy. Supported methods are limited to GET, POST, PATCH, DELETE

http endpoint paths will append the endpoint name to the begining of the path,
so no need to explicitly define the enpoint name. So the people paths will be
configured as.

http: {
    get: ['', '/:id'],
    post: [''],
    patch: ['/:id'],
    delete: ['/:id']
}

Which will result in these endpoints

  • GET /people
  • GET /people/:id
  • POST /people
  • PATCH /people/:id
  • DELETE /people/:id

Adding Authentication and Authorisation

The framework uses express under the hood and exposes the express
object as app. Which you can use to plugin standard express middlware
to do things that the api does not provide pre and post request.

External dependencies

  • MongoDB database