{"id":28438049,"url":"https://github.com/migliorelli/trunker","last_synced_at":"2026-03-15T01:08:13.159Z","repository":{"id":303944164,"uuid":"994391581","full_name":"migliorelli/trunker","owner":"migliorelli","description":"A lightweight Express.js middleware to help you implement feature flags.","archived":false,"fork":false,"pushed_at":"2025-08-17T02:21:53.000Z","size":94,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-17T02:28:44.401Z","etag":null,"topics":["express","express-middleware","feature-flags","feature-flags-management","middleware","nodejs","trunk-based-development"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/trunker ","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/migliorelli.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,"zenodo":null}},"created_at":"2025-06-01T20:48:22.000Z","updated_at":"2025-08-17T02:21:56.000Z","dependencies_parsed_at":"2025-07-10T17:00:14.253Z","dependency_job_id":null,"html_url":"https://github.com/migliorelli/trunker","commit_stats":null,"previous_names":["migliorelli/trunker"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/migliorelli/trunker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migliorelli%2Ftrunker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migliorelli%2Ftrunker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migliorelli%2Ftrunker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migliorelli%2Ftrunker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/migliorelli","download_url":"https://codeload.github.com/migliorelli/trunker/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/migliorelli%2Ftrunker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274463687,"owners_count":25290115,"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","status":"online","status_checked_at":"2025-09-10T02:00:12.551Z","response_time":83,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-middleware","feature-flags","feature-flags-management","middleware","nodejs","trunk-based-development"],"created_at":"2025-06-06T00:38:55.629Z","updated_at":"2026-03-15T01:08:08.112Z","avatar_url":"https://github.com/migliorelli.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trunker\n\n\u003cimg src=\"trunker.png\" alt=\"Trunker\" style=\"width: 150px; height: 150px\" /\u003e\n\nA lightweight Express.js middleware to help you implement feature flags. Easily manage and restrict access to routes based on static or dynamic flags, supporting both synchronous and asynchronous evaluation.\n\n## Features\n\n- Simple API for defining feature flags\n- Support for static and async flag evaluation\n- Restrict access to routes based on flags\n- Environment variable integration\n- TypeScript support out of the box\n\n## Installation\n\n```bash\nnpm install trunker\n```\n\n## Usage\n\n### Basic Example\n\n```ts\nimport express from \"express\";\nimport { createTrunker } from \"trunker\";\n\nconst app = express();\n\nconst trunker = createTrunker({\n  flags: {\n    betaFeature: { active: true },\n    legacyMode: { active: false },\n  },\n});\n\napp.use(trunker.middleware());\n\n// this route is accessible because betaFeature is active\napp.get(\"/beta\", trunker.restrict(\"betaFeature\"), (req, res) =\u003e {\n  res.send(\"Beta feature is enabled!\");\n});\n\n// this route is not accessible because legacyMode is not active\napp.get(\"/legacy\", trunker.restrict(\"legacyMode\"), (req, res) =\u003e {\n  res.send(\"Legacy mode is enabled!\");\n});\n\napp.listen(3000);\n```\n\n### Restricting Access to Routes\n\nYou can restrict access to routes using the `restrict` middleware:\n\n```ts\napp.get(\n  \"/admin\",\n  trunker.restrict(\"betaFeature\"),\n  (req, res) =\u003e {\n    res.send(\"Admin route with beta feature enabled\");\n  }\n);\n```\n\nYou can also restrict by multiple flags:\n\n```ts\napp.get(\n  \"/multi\",\n  trunker.restrict([\"betaFeature\", \"legacyMode\"]),\n  (req, res) =\u003e {\n    res.send(\"Route with multiple flags\");\n  }\n);\n```\n\n### Using Environment Variables\n\n```ts\nimport { fromEnv, createTrunker } from \"trunker\";\n\nconst trunker = createTrunker(fromEnv(process.env));\n```\n\nEnvironment variables should be prefixed with `TRUNKER_`, e.g.:\n\n```\nTRUNKER_BETA=true\nTRUNKER_LEGACY=false\n```\n\n### Dynamic Flags\n\n```ts\nflags: {\n  premiumUser: {\n    active: async (req) =\u003e {\n      // Custom logic, e.g., check user subscription\n      return await checkUserSubscription(req.user);\n    },\n  },\n}\n```\n\n### Checking Flags Manually\n\n```ts\nimport { isFlagActive } from \"trunker\";\n\napp.get(\"/some-route\", async (req, res) =\u003e {\n  if (await isFlagActive(req, \"betaFeature\")) {\n    res.send(\"Feature enabled\");\n  } else {\n    res.status(403).send(\"Not available\");\n  }\n});\n```\n\n### Custom Error Responses\n\nYou can customize the error response format:\n\n```typescript\nconst trunker = createTrunker({\n  flags: { ... },\n  error: { \n    format: \"json\", // required. `json` or `plain` \n    key: \"message\",  // optional\n    statusCode: 403, // optional\n    template: \"You can't access this route: {{flag}} is disabled\" // optional\n  }, \n});\n```\n\n## API\n\n### `createTrunker(options)`\nCreates the middleware. Pass an object with a `flags` property. Returns an object with `middleware()` and `restrict()` methods.\n\n### `fromEnv(env, options?)`\nGenerates flag configuration from environment variables.\n\n### `isFlagActive(req, flagName)`\nChecks if a flag is active for the current request.\n\n### `trunker.middleware()`\nExpress middleware to attach flags to `req.trunker`.\n\n### `trunker.restrict(flagName | flagName[])`\nExpress middleware to restrict access based on one or more flags.\n\n## TypeScript\n\nThe middleware adds a `trunker` property to the Express `Request` type. You may need to import the type definitions for full type safety.\n\n```ts\nimport { type Flags } from \"trunker\";\n\ndeclare module \"express-serve-static-core\" {\n  interface Request {\n    trunker: Flags;\n  }\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmigliorelli%2Ftrunker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmigliorelli%2Ftrunker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmigliorelli%2Ftrunker/lists"}