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

create-koa-web

v1.4.0

Published

The scaffolding of building Node Service with `Koa2 + TypeScript`.

Downloads

25

Readme

create-koa-web

The scaffolding of building Node Service with Koa2 + TypeScript.

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 |

Scaffolding Your First koa-web Project

Compatibility Note: koa-web requires Node.js version 14.18+, 16+.. However, some templates require a higher Node.js version to work, please upgrade if your package manager warns about it.

With NPM:

$ npm create koa-web@latest

With Yarn:

$ yarn create koa-web

With PNPM:

$ pnpm create koa-web

Then follow the prompts!

You can also directly specify the project name. For example, to scaffold a koa-web project, run:

# npm 6.x
npm create koa-web@latest koa-web-starter --template standard

# npm 7+, extra double-dash is needed:
npm create koa-web@latest koa-web-starter -- --template standard

# yarn
yarn create koa-web koa-web-starter --template standard

# pnpm
pnpm create koa-web koa-web-starter --template standard

Usage

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           // 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.