Skip to content

Getting Started

keiro

keiro (Kee-Ro) is a routing middleware compatible with NodeJS which uses moderm Web Standards.

Installation

Terminal window
npm add keiro

Setup

  • Directorysrc
    • main.ts
    • Directoryroutes ** All the routes are located here **
      • index.ts
  • package.json

For initialize the middleware we import the fileSystemRouter from keiro/node or keiro/web.

src/main.ts
import { fileSystemRouter } from "keiro/node";
import http from "node:http";
const port = 5000;
const origin = `http://localhost:${port}`;
const server = http.createServer(fileSystemRouter({ origin }));
server.listen(port, () => console.log(`Listening on ${origin}`));

We define the api handlers on the src/routes/, this can be changed.

src/routes/index.ts
import { defineHandler } from "keiro";
export default defineHandler(() => {
return Response.json({
hello: "world"
})
})

Then run main.ts on node you can install tsx and use tsx src/main.ts.