@emilo/requestify
v0.2.5
Published
Requestify is a lightweight Node.js HTTP framework for building server routes with full TypeScript support.
Readme
Requestify
npm i @emilo/requestifyimport { MongoClient } from "mongodb";
import { Requestify } from "@emilo/requestify";
(async () => {
const isDev = process.env.NODE_ENV !== "production";
const mongodb = new MongoClient("_fake_mongo_url_");
await mongodb.connect();
const db = mongodb.db("my-db");
const app = Requestify({
data: { db, b: 1 },
global_middleware: [
async ({ req, res, data, params, errorHandler }) => {},
...(isDev ? [() => true] : []),
],
routes: [
{
path: "/",
method: "GET",
handler: ({ req, res, data, params, errorHandler }) => {},
middleware: [],
},
],
error_handler: async ({ req, res, data, error }) => {},
not_found_handler: async ({ req, res, data, errorHandler }) => {},
});
return app;
})()
.then((app) => app.listen(3000))
.catch((error) => {
console.error("Failed to start application:", error);
process.exit(1);
});