Design for quickly developing Web applications using Node.js
Based on koa
npm install @axiosleo/koapp
npx @axiosleo/koapp init <app-name> -d <optional-dir>
# show help info
# npx @axiosleo/koapp init -h
const { KoaApplication, Router, success } = require("@axiosleo/koapp");
const handle = async (ctx) => {
success({
message: "Hello World!",
});
};
const router = new Router("/test", {
method: "any",
handlers: [handle],
});
const app = new KoaApplication({
port: 8088,
listen_host: "localhost", // 0.0.0.0 for public access
routers: [router],
});
app.start();
// open http://localhost:8088/test
- Validation
see validatorjs for more rule examples
see
Router
examples for more usage: tests/bootstrap.js
const { Router } = require("@axiosleo/koapp");
const router = new Router("/test", {
method: "any",
validator: {
// url params, like `/test/{:id}`, the 'id' is required and must be an integer
params: {
id: "required|integer",
},
query: {
name: "required|string",
},
body: {
age: "required|integer",
}
}
handlers: [],
});
This project is open-sourced software licensed under MIT.