tiger

Tiger

Tiger is a simple framework of lightweight process.

Use cases

see Structure and Plugin for more information.

Logo is generated from Wikipedia, the original script is under GPL license.

Usage

npm install tiger-server --save

and create server.ts:

import { defineServer, http, cron, queue } from "tiger-server";
import type { QueueModule, CronModule, HttpModule } from "tiger-server";

export default defineServer(async (tiger) => {
  await tiger.use(http, cron, queue);

  await tiger.define<QueueModule<{message: string}>>({
    id: "hello",
    target: "queue:hello",
    async process(_state, message) {
      this.log(`Message received: ${JSON.stringify(message)}`);
    }
  });

  await tiger.define<CronModule<{count: number}>>({
    id: "cron",
    target: "cron:*/5 * * * * *",
    async process({ count = 0 }) {
      count++;
      await this.notify("queue:hello", { count });
      return { count }
    }
  });

  await tiger.define<HttpModule>({
    id: "request",
    target: "http:/hello",
    async process(_state, { req, res }) {
      await this.notify("queue:hello", { message: "request recieved" });
      res.send("success!")
    }
  });
});

Run it with Node.jsĀ 22.6+:

npx tiger-server run server.ts