Installations
npm install koa-micro-ts
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
22.12.0
NPM Version
10.9.0
Score
62.8
Supply Chain
95.6
Quality
85.6
Maintenance
100
Vulnerability
98.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
sebhildebrandt
Download Statistics
Total Downloads
12,015
Last Day
4
Last Week
32
Last Month
274
Last Year
2,407
GitHub Statistics
MIT License
7 Stars
160 Commits
3 Watchers
1 Branches
1 Contributors
Updated on Jan 30, 2025
Bundle Size
742.31 kB
Minified
274.42 kB
Minified + Gzipped
Package Meta Information
Latest Version
4.1.1
Package Id
koa-micro-ts@4.1.1
Unpacked Size
168.29 kB
Size
35.66 kB
File Count
39
NPM Version
10.9.0
Node Version
22.12.0
Published on
Jan 30, 2025
Total Downloads
Cumulative downloads
Total Downloads
12,015
Last Day
33.3%
4
Compared to previous day
Last Week
45.5%
32
Compared to previous week
Last Month
9.2%
274
Compared to previous month
Last Year
-2.2%
2,407
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
koa-micro-ts
Microservice framework based on koa
_ _ _
| | _____ __ _ _ __ ___ (_) ___ _ __ ___ | |_ ___
| |/ / _ \ / _` |_____| '_ ` _ \| |/ __| '__/ _ \ _____| __/ __|
| < (_) | (_| |_____| | | | | | | (__| | | (_) |_____| |_\__ \
|_|\_\___/ \__,_| |_| |_| |_|_|\___|_| \___/ \__|___/
Koa TypeScript Microservice Framework - batteries included
Quick Start
This package provides a minimalistic, simple to use, koa based micro service template. A few common used middleware packages are already included. To keep it small as possible, we added some own tiny libraries like CORS, JWT-wrapper, auto routes, logger, validators, APIdoc, API-History Fallback. Included middleware/libs:
- body parser (now configurable since version 3) - detailed docs for all bodyparser options BODYPARSER.md
- basic router
- auto router - smart directory based auto-generation of routes - detailed docs AUTOROUTES.md
- CORS - detailed docs CORS.md
- JWT - detailed docs JWT.md
- static files serving - detailed docs STATIC.md
- API history fallback functionality APIFALLBACK.md
- validators - detailed docs VALIDATORS.md
- health API endpoint - detailed docs HEALTH.md
- graceful shutdown - detailed docs SHUTDOWN.md
- logger - detailed docs LOGGER.md
- parsing command line arguments - detailed docs ARGS.md
- dev/production mode detection - see below in this README.md
- catch errors - detailed docs CATCHERRORS.md
- request stats - detailed docs REQUESTSTATS.md
- integrated API doc - detailed docs APIDOC.md
Most of these modules can be enabled with just one line of code. Configuration is super simple and lets you create your micro service within minutes.
Version 4 - Breaking Change
app.autoRoute()
is now an async function.
So you need to call it within an async/await block ... here an example:
const main = async () => {
await app.autoRoute(path.join(__dirname, '/routes'), '/api/v1');
...
app.start(3000);
}
main()
Version 3 - Breaking Change
app.bodyParser()
needs to be called now. Please call this before adding any
routes. This has a configuration object, detailed documentation on body parser
options can be found here BODYPARSER.md
app.bodyParser({ multipart: true })
Installation
1$ npm install koa-micro-ts
Usage
Here is an example how you can use koa-micro-ts
. Depending on your use case
most of the things here are optional and only required if you want to use them:
1import { app, Application } from "koa-micro-ts"; 2import { join } from "path"; 3 4// setting variables only for demo purposes. 5// You can set this as environment variables 6process.env.APP_NAME = "micro-service"; 7process.env.VERSION = "1.0.0"; 8 9// enable body parser (with desired options) 10app.bodyParser({ multipart: true }); 11 12// enable helpth endpoint (defaults to tow endpoints /live and /ready) 13app.health(); 14 15// enable helmet (optional) 16app.helmet(); 17 18// enable cors (optional) 19app.cors(); 20 21// parse command line params (optional) 22app.parseArgs(); 23 24// catch uncatched errors - must be 'used' before adding routes 25app.catchErrors(); 26 27// set up static server (optional) 28app.static(join(__dirname, "/public")); 29 30// using router 31const router: any = app.newRouter(); 32 33router.get("/route", (ctx: Application.Context, next: Application.Next) => { 34 ctx.body = "OK from static route"; 35}); 36 37app.useRouter(router); 38 39// enable gracefull shutdown (optional) 40app.gracefulShutdown(); 41 42app.ready = true; // /health /ready endpoint now returns true 43app.start(3000);
Have a look at the function reference APP.md for all options
Auto-Routes
This is one of the smart features of this package:
autoRoute
allows you to just write your API endpoints and place them into a
directory structure. When calling
await app.autoRoute(...directory..., mountpoint)
, this directory will be
parsed recursivly and all TypeScript files with extension .route.ts
are added
as routes. All routes then will be mounted to the given mountpoint
. Your API
structure then matches exactly your directory structure. This makes writing and
maintaining your API endpoints super simple.
Detailed docs with examples can be found here: AUTOROUTES.md
Dev / Production Mode
The app
instance has a development
property that is set to true when
providing a --dev
or --development
argument during startup or if the
environment variable DEVELOPMENT
exists.
You can use this property e.g. like this:
if (app.development) {
...
}
Examples
The example in the path examples
shows how to use koa-micro-ts
and
- enable health endpoint
- enable helmet
- enable cors
- serving static pages
- using standard router
- using auto routes
Building Example App
git clone https://github.com/sebhildebrandt/koa-micro.git
cd koa-micro
npm install
npm run build-example
npm run example
Now try the following routes in your browser:
Static Page:
http://localhost:3000/
Standard Routes
http://localhost:3000/route
http://localhost:3000/route2
Health Routes
http://localhost:3000/liveness
http://localhost:3000/readyness
Routes from autoRouter
http://localhost:3000/api/v1/
http://localhost:3000/api/v1/hello/
http://localhost:3000/api/v1/error/
http://localhost:3000/api/v1/resource/?param=value
Advanced usage
As koa-micro-ts
uses some external packages, you can also refer to the
documentation of the used packages to see their options:
License 
The
MIT
License (MIT)Copyright © 2025 Sebastian Hildebrandt, +innovations.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Further details see LICENSE file.

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
8 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 6
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3.8
/10
Last Scanned on 2025-02-17
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More