@jugnuagrawal/express-mongoose-crud

A node js library to generate a microservice capable of doing CRUD operation over REST API for the given schema structure.

Usage no npm install needed!

<script type="module">
  import jugnuagrawalExpressMongooseCrud from 'https://cdn.skypack.dev/@jugnuagrawal/express-mongoose-crud';
</script>

README

express-mongoose-crud

This tool to generate microservice based on express js and mongoose js which can do CRUD operation using REST APIs.

Use like a node module

$ npm install --save express-mongoose-crud
  • import express-mongoose-crud to your project and pass the schema json.
const generator = require('express-mongoose-crud');

var schema = {
    "name": "User Details",
    "basePath": "/user",
    "port": 3000,
    "database": "users",
    "schema": {
        "name": "String",
        "email": {
            "type": "String",
            "unique": true,
            "required": true
        },
        "password": "String",
        "contactNos": [
            {
                "code": "String",
                "number": "Number"
            }
        ],
        "gender": "String",
        "address": {
            "houseNo": "String",
            "street": "String",
            "city": "String",
            "state": "String",
            "country": "String",
            "pincode": "Number"
        }
    }
}

generator.createProject(schema);

Use with command line interface

$ npm install -g express-mongoose-crud

$ misgen -h

Usage: misgen [options] <name>

Options:

  -V, --version  output the version number
  -d, --dir      Directory name 
  -h, --help     output usage information


# [-d generates microservice for all the schema files in a directory

$ misgen schema.json

#The project folder will be generated at the location of schema.json file

Schema JSON Structure

{
    "name":"User Details", //Required. Name of this microservice
    "basePath":"/user", //Optional. API URL of this microservice
    "port":3000, //Optional. Port number in which this microservice will be running
    "database":"users", //Optional. Name of database in which this microservice will create it's collection
    "schema":{
        //mongoose schema
    }
}
  • Example mongoose schema
{
    "name": "String",
    "email": {
        "type": "String",
        "unique": true,
        "required": true
    },
    "password": "String",
    "contactNos": [
        {
            "code": "String",
            "number": "Number"
        }
    ],
    "gender": "String",
    "address": {
        "houseNo": "String",
        "street": "String",
        "city": "String",
        "state": "String",
        "country": "String",
        "pincode": "Number"
    }
}

License

MIT