1.3.3 • Public • Published


    NPM version build status Test coverage David deps Known Vulnerabilities npm download


    The tool only builds the underlying code, atomic operations on the database, generates interfaces and some auxiliary code for quick development and does not participate in any business logic.

    Dependency Description

    Code building tools based on eggjs and sequelize, In order for the code to work, you should use the command egg-coding i to install the necessary dependencies before starting your application.

    Code Style


      "extends": "eslint-config-egg",
      "rules": {
        "indent": [2, 4,{ "SwitchCase": 1 }],
        "comma-dangle": ["error", "never"],


    Global installation

    $ npm i egg-coding -g

    Directory Structure

    After the build is completed, there will be the following directory structure.

    ├── package.json
    ├── app.js
    ├── app
    | ├── router.js
    │ ├── base_context_class.js (provides a base class for easy extension)
    │ ├── controller (control layer)
    │ | └── user.js
    │ ├── service (business logic layer)
    │ | └── user.js
    │ ├── router
    │ | └── user.js
    │ ├── model (database model)
    │ | └── user.js
    │ ├── rules (parameter verification rules)
    │ | └── user.json
    │ ├── errors(DIY exception class)
    │ | └── client_error.js
    │ ├── utils (tool)
    │ | └── date_format.js
    ├── config
    | ├── plugin.js (plugin list)
    | ├── config.default.js (default configuration)
    └── test
        ├── middleware
        | └── response_time.test.js
            └── home.test.js

    Development Specifications

    • The model is the same as the database table name, for example, app/model/student.js corresponds to the student table.
    • Each model has a router module in the ${baseDir}/app/router directory and is eventually referenced in ${baseDir}/app/router.js
    • Turn on timestamp and soft delete
    • Parameter validation rules are all placed in the ${baseDir}/app/rules directory
    • All controllers and services inherit the BaseController and BaseService provided by base_context_class
    • Non-code exceptions are defined in errors/client_error.js
    • Time stamp unified formatting
    • Send response data using plugin egg-response
    • Handling exceptions using the plugin egg-error-handler


    The interface provided by default, where order is the table name

    'use strict';
     * @param {Egg.Application} app - egg application
    Module.exports = app => {
        Const { router, controller } = app;
        Router.resources('/api/v1/order', controller.order);'/api/v1/order/createMany', controller.order.createMany);'/api/v1/order/deleteMany', controller.order.deleteMany);'/api/v1/order/updateMany', controller.order.updateMany);'/api/v1/order/findOne', controller.order.findOne);'/api/v1/order/findByExample', controller.order.findByExample);

    see more

    Rapid development

    First step

    Initialize a project with egg-init

    $ egg-init egg-project --type=simple

    Second step

    Install the dependency package with egg-coding i

    $ egg-coding i

    third step

    Use egg-coding init to initialize the startup file, default configuration, and enable the plugin

    $ egg-coding init

    Modify the default configuration as needed

    fourth step

    Create a database model using egg-coding model

    $ egg-coding model model1 model2 model3...

    Modify the model as needed, write table fields

    Fifth step

    Build code with egg-coding curd

    $ egg-coding curd -p /api/v1 -r

    Modify verification rules as needed

    Local debugging

    $ npm run dev

    The default port is 7834, The whole process will not exceed 10 minutes

    Command Parameters

    Get help with --help or -h

    $ egg-coding -h


    $ egg-coding i -h
    $ egg-coding init -h
    $ egg-coding model -h
    $ egg-coding curd -h

    Asking questions

    Please go to egg issues for asynchronous communication.




    npm i egg-coding

    DownloadsWeekly Downloads






    Unpacked Size

    40.3 kB

    Total Files


    Last publish


    • iamljw