1.4.11 • Published 3 months ago

@ireves/common-api v1.4.11

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
3 months ago

common-api

Simple backend framework with JWT and MySQL support.

Installation into an existing project

To install common-api as a dependency of your Node.js project:

npm install @ireves/common-api

common-api is made with TypeScript.

How to use

import CommonApi from "@ireves/common-api";
import path from "path";

CommonApi.initializeConfig(config);
CommonApi.initializeScheduler(schedules);

runExpressApp();

function runExpressApp() {
    const app = new CommonApi.App(
        path.join(__dirname, "router"),
        [],
        CommonApi.defaultRouterMiddlewares,
        []
    );
    app.run(
        config.port,
        () => {
            console.info(`Server started with port: ${config.port}`);
        },
        (error) => {
            CommonApi.logger.error(error);
        }
    );
}
const config: CommonApi.Config = {
    jwtSecret: "secret",
    db: {
        host: "127.0.0.1",
        port: 3306,
        user: "root",
        password: "password",
        database: "db",
    },
};
const schedules: CommonApi.Schedule[] = [
    name: "testSchedule",
    cron: "00 00 00 * * *",
    job: () => {
        console.log("Welcome!")
    },
];