{"id":20525838,"url":"https://github.com/trackap/expressmultithread","last_synced_at":"2025-04-14T03:51:35.122Z","repository":{"id":188899732,"uuid":"671480924","full_name":"Trackap/ExpressMultithread","owner":"Trackap","description":"Fast, light-weight and low dependency Express.js multithreaded router","archived":false,"fork":false,"pushed_at":"2025-03-11T22:53:29.000Z","size":1425,"stargazers_count":3,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-27T17:51:46.161Z","etag":null,"topics":["express","express-js","expressjs","multithread","multithreading","multithreading-library","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/expressmultithread","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Trackap.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-27T12:17:16.000Z","updated_at":"2024-12-11T08:07:17.000Z","dependencies_parsed_at":null,"dependency_job_id":"962cd045-d4fd-484b-8e41-b1b7784ebf53","html_url":"https://github.com/Trackap/ExpressMultithread","commit_stats":null,"previous_names":["trackap/expressmultithread"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trackap%2FExpressMultithread","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trackap%2FExpressMultithread/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trackap%2FExpressMultithread/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Trackap%2FExpressMultithread/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Trackap","download_url":"https://codeload.github.com/Trackap/ExpressMultithread/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248819353,"owners_count":21166474,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","express-js","expressjs","multithread","multithreading","multithreading-library","typescript"],"created_at":"2024-11-15T23:10:00.645Z","updated_at":"2025-04-14T03:51:35.100Z","avatar_url":"https://github.com/Trackap.png","language":"TypeScript","readme":"# Express Multithread Router\nFast, light-weight and low dependency [Express.js](https://www.npmjs.com/package/express) multithreaded router.\n\n[![Tests](https://github.com/Trackap/ExpressMultithread/actions/workflows/tests.yml/badge.svg)](https://github.com/Trackap/ExpressMultithread/actions/workflows/tests.yml)\n\nInstallation\n-\nThis project require typescript and express.\n\n```shell\nnpm i expressmultithread\n```\n\nUsage\n-\n\n1. Import express \u0026 multithreaded router :\n```ts\n// file index.ts\nimport express from 'express';\nimport Router from 'expressmultithread';\n```\n\n2. Create your express app, use router and import controllers :\n```ts\n// file index.ts\nconst App = express();\nApp.use(\"/\", Router.router);\nRouter.importControllers(\"./controllers\");\nApp.listen(3000, () =\u003e console.info(\"Listening on port 3000\"));\n```\n\n3. Create a controllers directory and create a file 'example.ts' :\n```ts\n// file example.ts\nimport { controller, route } from 'expressmultithread/dist/decorators';\nimport { Request, Response } from 'express';\n\n@controller()\nexport class ExampleController {\n    @route(\"get\", \"/hello\")\n    public hello(_req: Request, res: Response) {\n        res.status(200).send(\"Hello world!\");\n    }\n}\n```\n\n4. Create a configuration file, at root of project :\n```ts\n// file em.config.ts\nimport { BaseConfig } from \"expressmultithread/dist/types\";\n\n/* Define a config */\nconst config : BaseConfig = {\n    threadCount: 2 // Define number of thread which run your web server\n};\n\n/* Export it as default*/\nexport default config;\n```\n\nNow you can run index.ts and open the following url http://localhost:3000/hello.\nIf you had trouble with this example you can see [example ReadMe](https://github.dev/Trackap/ExpressMultithread/tree/main/examples/exampleReadMe).\n\nToo many threads created ?\nYou  just have to adjust it, with the configuration file.\n\nAPI\n-\n\n##### Imports:\n```ts\nimport Router from 'expressmultithread';\nimport { router, controller } from 'expressmultithread/dist/decorators';\nimport { ... } from 'expressmultithread/dist/types';\nimport Config from 'exressmultithread/dist/config';\n```\n\n##### Prototypes:\n###### Config (Object):\n\n`Properties :`\n - threadCount (property): Desired number of thread to launch (type: `number`);\n - plugins (property): Array of path to plugin file (type: `string[]`);\n - cleanRequest (method): Clean request function (type: `(req: Request) =\u003e Request`);\n\n###### Router (Object):\n`Properties :`\n - router (property): ExpressRouter to use. (type: `ExpressRouter`)\n\n`Methods :`\n - importControllers (method): Define directory to fetch routes (type: `(path: string | string[]) =\u003e void`)\n - use (method): Use a middleware on all routes (type: `(path: string, ...args: Serializable[]) =\u003e void`)\n - unuse (method): Unuse a middleware or remove all used middlewares (type: `(middleware?: string, ...args: Serializable[]) =\u003e void`)\n\nUsefull informations\n-\nThe object request received in your functions is a light version of the original one, you can customize what's inside by following the [overrideReq example](https://github.dev/Trackap/ExpressMultithread/tree/main/examples/overrideReq).\n\nThe object response received in your functions is a total override object, it was overrided following the [Express API Documentation 4.x](https://expressjs.com/fr/4x/api.html#res).\nPlease note that transferred informations between threads must be serialisable data, res functions calls give content of the call to the main thread it means you can't pass functions in any res methods.\n\nMiddlewares passed in controller or route args, can't be error middleware, this is not handled by the multithreadedrouter, despite, you can handle errors with the main thread following the [errorHandling example](https://github.dev/Trackap/ExpressMultithread/tree/main/examples/errorHandling).\n\nPlease note that all path sent in args to plugins are resolve with the current working directory.\n\nConfig file\n-\nYou can a file named `em.config.ts` which must export as default an object typed with the following type :\n```ts\nimport { BaseConfig } from \"expressmultithread/dist/types\";\n```\nIn this object you will be able to define different variables :\n* threadCount (number): Number of child thread to launch\n* cleanRequest ((req: Request) =\u003e Request): A function which let you pass more args in your Request variables\n* plugins (string[]): Path array of plugin files\n* overrideConsole (boolean): Enable/Disable identifier on console usages\n* debug (boolean): Enable/Disable debug of module\n* verbose (boolean): Enable/Disable extra logging in console\n* restartThreads (boolean): Enable/Disable automatic restart of a new thread in case of crash\n\nMore examples\n-\nCheck [examples folder](https://github.dev/Trackap/ExpressMultithread/tree/main/examples) for more examples\n\nLicense\n-\nExpressMultithread is [MIT Licensed](https://github.com/Trackap/ExpressMultithread/blob/main/LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackap%2Fexpressmultithread","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftrackap%2Fexpressmultithread","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftrackap%2Fexpressmultithread/lists"}