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

koa2-builder

v1.1.0

Published

It is a backend builder for node.js with koa 2.x framework

Downloads

241

Readme

koa2-builder

koa2-builder is a tool that can help you to build up the back-end structure with node.js koa2 framework. koa2-builder will create several essential folders for you before you start to design your APIs. All you need to do is adjust the configuration, review the purpose of the folders, start to add the package you need, and that is it.

Features

  • api documentation
  • mocha test with mochawesome test report
  • socket io
  • pm2 for production mode
  • nodemon for developer mode
  • developer and production configuration selector
  • simple role base access control
  • ajv for validation
  • json web token
  • logs for error
  • logs for receive and response
  • mongo connection
  • redis connection
  • bcrypt, aes256 encode and decode
  • json web token validation
  • bee-queue worker
  • eslint support

Installlation

npm install -g koa2-builder

Usage

Usage: koa2-builder <dirName>

Options:

-V, --version  output the version number
-h, --help     output usage information

Running Your Project

Install dependencies

npm install

Start node server in developer mode

npm run dev

Start node server in production mode

npm run prd

Start worker in developer mode

npm run tester

Start worker in production mode

npm run worker

Pre-built folders

your project dirName
├┬ bin (project start here)
│├ config
││├ development.js (config for developer mode)
││├ index.js (mode selector)
││├ log.js (config of output log format)
││├ production.js (config for production mode)
││└ rbac.js (simple rbac config)
│├ controllers
││└ rbac.js (simple rbac config)
│├ error
││├ apiError.js (error output defined)
││└ apiErrorNames.js (error information definition)
│├ events
││├ index.js (event exporter)
││├ server.js (errors event for server)
││└ socketIo.js (example of socket io event) │├ jobs
││├ dispatcher.js (dispatch the jobs to worker)
││└ worker.js (worker running here)
│├ logs
││├ error (all the error logs go here)
││└ response (all the received and responded logs go here)
│├ middlewares
││├ jwt.js (json web token middleware)
││├ rbac.js (role base access control middleware)
││└ response.js (response formatting middleware)
│├ models
││├ dbModel.js (database selector)
││├ rbacModel.js (role base access control model)
││├ redisInviteModel.js (redis model sample)
││└ userModel.js (user model sample)
│├ public
││├ doc (apis documentation goes here)
││└ report (mocha test report goes here)
│├ routes
││├ index.js (index for routing)
││└ user.js (user routing sample)
│├ test
││└ user.test.js (user module test sample)
│├ tmp
│├ utils
││├ crypto.js (utility for encrypt and decrypt data)
││├ email.js (utility for sending the email)
││├ log_util.js (utility for formatting the log)
││└ validate.js (utility for validate the json schema)
└└ views

You can be free to adding your own packages or remove unnecessary packages came with koa2-builder.

To generate APIs Document

npm install apidoc -g

Run apidoc generator under the (default port is 3088)

npm run doc

http://127.0.0.1:3088/doc/ You can modified the port in developer.js and production.js in config folder.

To generate the Test Report

To generate the test report using mocha (default port is 3088)

npm run test

http://127.0.0.1:3088/report/ You can modified the port in developer.js and production.js in config folder.

Your project logs location

Response logs

<dirName>/logs/response/response--YYYY-MM-DD.log

Error logs

<dirName>/logs/error/error--YYYY-MM-DD.log

Your project output format

If there is no error occured, code will be 0 Standard output format example

{
  "code": 0,
  "message": "success"
}

Standard output format with result return example

{
  "code": 0,
  "message": "success",
  "result": {
    ...
  }
}

Standard output format with multi results return example

{
  "code": 0,
  "message": "success",
  "result": [{
      ...
  }]
}

If there is an error which is not from the server api, it will give the code > 0 Error output format examples

{
  "code": 11000,
  "message": "E11000 duplicate key error collection: users index: account_1 dup key: { : \"f124226244\" }"
}

If there is an error which is from the server api, it will give ethe code < 0 Error output format examples

{
  "code": -1,
  "message": "unknown error"
}