GithubHelp home page GithubHelp logo

zeffon / koa-web Goto Github PK

View Code? Open in Web Editor NEW
8.0 1.0 2.0 723 KB

The scaffolding of building Node Service with Koa2 + TypeScript.

License: MIT License

JavaScript 2.92% TypeScript 97.08%
koa2 koa-web koa2-demo typescript koa-typescript koa2-starter

koa-web's Introduction

Language : English | 简体中文

Koa Web

The scaffolding of building Node Service with Koa2 + TypeScript.

npm release license node ci

Features

The presets template are:

Template Feature
Mini Exception, Validator, API Doc
Lite Mini + Database
Standard Lite + Auth, Log
Full Standard + Redis, Cache, Test-Unit
Generator generate app module code and database table
  • 💡 TypeScript: support TypeScript
  • 🚀 Exception:Global exception handling
  • ✈️ Validator:Practical and efficient data validation usage
  • 📝 API Doc:API Doc UI
  • 🍀 Database:Support for Sequelize connections
  • ✍️ Auth:General JWT authorization
  • 📖 Log:Log SQL and error logs
  • 🔥 Redis:Support for Redis database connections
  • Cache:Support for Local Cache
  • Test-Unit:Support unit test

Usage

The koa-web supports quick creation of project through the create command.

Scaffolding Your First koa-web Project

With NPM:

$ npm create koa-web@latest

With Yarn:

$ yarn create koa-web

With PNPM:

$ pnpm create koa-web

Here are the default main npm scripts in a scaffolded koa-web-starter project:

{
  "scripts": {
    "dev": "nodemon", // start dev serve
    "build": "tsc && tsc-alias", // build project
    "serve": "node dist/app.js" // start build serve
  }
}
cd koa-web-starter

npm install

npm run dev

# please open in: http://127.0.0.1:3100/api/doc.html

Project Layout

This is template-koa-standard layout

├── src
│   ├── app.ts              // koa start
│   ├── app                 // app modules
│       ├── api             // controller layer
│       ├── dto             // Data Transfer Object
│       ├── model           // sequelize model
│       ├── service         // service processing layer
│       └── share           // common util directory
│   ├── config              // env config
│   ├── typings             // ts type
│   └── core                // core mudules
│       ├── init.ts         // core start
│       ├── global.ts       // global var
│       ├── tool.ts         // tool
│       ├── exception       // global exception
│       ├── swagger         // api docs and validator
│       ├── database        // database modules
│       ├── auth            // auth modules
│       └── log             // log modules
├── .gitignore
├── nodemon.json            // nodemon watch files to run serve
├── package.json
├── README.md
└── tsconfig.json

Generator

koa-web-generator can quickly generate koa-web's app module code and database table.

Generate content: model, service, API, and DTO files.

Automatically generate database tables is turned off by default.

  1. pull project & install deps

    pnpm create koa-web koa-web-generator --template generator
    
    cd ./koa-web-generator
    
    pnpm install
  2. Add the models you want to generate in ./src/index.ts

    Every model is already contains id, created_at, updated_at, deleted_at.

    const models: ModelProps[] = [
      {
        name: 'user_alpha',
        comment: 'user comment',
        fields: [
          {
            fieldName: 'username',
            type: 'STRING(20)',
            allowNull: false,
            unique: 'username_idx',
          },
          {
            fieldName: 'password',
            type: 'STRING',
            allowNull: false,
            comment: 'password comment',
          },
          {
            fieldName: 'type',
            type: 'BOOLEAN',
            defaultValue: '0',
          },
        ],
      },
    ]
  3. start generate

    pnpm start

After generation is complete, you can get such as files in ./src(model | service | api | dto) You can copy these files into your koa-web project.

Don't forget, the file ./src/model/index/ts also has generated content.

License

MIT

Copyright (c) 2022-present, Zeffon Wu

koa-web's People

Contributors

fossabot avatar pauloferreira25 avatar zeffon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.