{"id":14989644,"url":"https://github.com/treblle/treblle-node","last_synced_at":"2025-04-12T00:31:33.596Z","repository":{"id":40317544,"uuid":"314563611","full_name":"Treblle/treblle-node","owner":"Treblle","description":"The official Treblle SDK for NodeJS/ExpressJS/NestJS. Seamlessly integrate Treblle to manage communication with your dashboard, send errors, and secure sensitive data.","archived":false,"fork":false,"pushed_at":"2024-04-15T13:50:49.000Z","size":55,"stargazers_count":37,"open_issues_count":0,"forks_count":3,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-04-16T09:02:04.637Z","etag":null,"topics":["api","api-monitoring","api-observability","backend","developer-tool","express","expressjs-api","logging","nestjs","nodejs","nodejs-expressjs","rest-api","restful-api","sdk","treblle","treblle-sdk"],"latest_commit_sha":null,"homepage":"https://www.treblle.com/","language":"JavaScript","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/Treblle.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":"2020-11-20T13:34:21.000Z","updated_at":"2024-05-23T08:53:29.978Z","dependencies_parsed_at":"2024-05-23T09:03:30.321Z","dependency_job_id":null,"html_url":"https://github.com/Treblle/treblle-node","commit_stats":{"total_commits":40,"total_committers":6,"mean_commits":6.666666666666667,"dds":"0.42500000000000004","last_synced_commit":"3f9c1ae719e63ed0237be0b4479f6a1ac594dfa7"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Treblle%2Ftreblle-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Treblle%2Ftreblle-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Treblle%2Ftreblle-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Treblle%2Ftreblle-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Treblle","download_url":"https://codeload.github.com/Treblle/treblle-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248501265,"owners_count":21114640,"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":["api","api-monitoring","api-observability","backend","developer-tool","express","expressjs-api","logging","nestjs","nodejs","nodejs-expressjs","rest-api","restful-api","sdk","treblle","treblle-sdk"],"created_at":"2024-09-24T14:18:41.835Z","updated_at":"2025-04-12T00:31:33.568Z","avatar_url":"https://github.com/Treblle.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/b268ae9e-7c8a-4ade-95da-b4ac6fce6eea\"/\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n\n# Treblle\n\n\u003ca href=\"https://docs.treblle.com/en/integrations\" target=\"_blank\"\u003eIntegrations\u003c/a\u003e\n\u003cspan\u003e\u0026nbsp;\u0026nbsp;•\u0026nbsp;\u0026nbsp;\u003c/span\u003e\n\u003ca href=\"http://treblle.com/\" target=\"_blank\"\u003eWebsite\u003c/a\u003e\n\u003cspan\u003e\u0026nbsp;\u0026nbsp;•\u0026nbsp;\u0026nbsp;\u003c/span\u003e\n\u003ca href=\"https://docs.treblle.com\" target=\"_blank\"\u003eDocs\u003c/a\u003e\n\u003cspan\u003e\u0026nbsp;\u0026nbsp;•\u0026nbsp;\u0026nbsp;\u003c/span\u003e\n\u003ca href=\"https://blog.treblle.com\" target=\"_blank\"\u003eBlog\u003c/a\u003e\n\u003cspan\u003e\u0026nbsp;\u0026nbsp;•\u0026nbsp;\u0026nbsp;\u003c/span\u003e\n\u003ca href=\"https://twitter.com/treblleapi\" target=\"_blank\"\u003eTwitter\u003c/a\u003e\n\u003cspan\u003e\u0026nbsp;\u0026nbsp;•\u0026nbsp;\u0026nbsp;\u003c/span\u003e\n\u003ca href=\"https://treblle.com/chat\" target=\"_blank\"\u003eDiscord\u003c/a\u003e\n\u003cbr /\u003e\n\n  \u003chr /\u003e\n\u003c/div\u003e\n\nAPI Intelligence Platform. 🚀\n\nTreblle is a lightweight SDK that helps Engineering and Product teams build, ship \u0026 maintain REST-based APIs faster.\n\n## Features\n\n\u003cdiv align=\"center\"\u003e\n  \u003cbr /\u003e\n  \u003cimg src=\"https://github.com/user-attachments/assets/02afd9f5-ab47-48ff-929a-0f3fcddcca34\"/\u003e\n  \u003cbr /\u003e\n  \u003cbr /\u003e\n\u003c/div\u003e\n\n- [API Monitoring \u0026 Observability](https://www.treblle.com/features/api-monitoring-observability)\n- [Auto-generated API Docs](https://www.treblle.com/features/auto-generated-api-docs)\n- [API analytics](https://www.treblle.com/features/api-analytics)\n- [Treblle API Score](https://www.treblle.com/features/api-quality-score)\n- [API Lifecycle Collaboration](https://www.treblle.com/features/api-lifecycle)\n- [Native Treblle Apps](https://www.treblle.com/features/native-apps)\n\n\n## Treblle for Node\n\n[![Latest Version](https://img.shields.io/npm/v/treblle)](https://img.shields.io/npm/v/treblle)\n[![Total Downloads](https://img.shields.io/npm/dt/treblle)](https://img.shields.io/npm/dt/treblle)\n[![MIT Licence](https://img.shields.io/npm/l/treblle)](LICENSE.md)\n\nTreblle makes it super easy to understand what’s going on with your APIs and the apps that use them. Just by adding Treblle to your API out of the box you get:\n\n- Real-time API monitoring and logging\n- Auto-generated API docs with OAS support\n- API analytics\n- Quality scoring\n- One-click testing\n- API managment on the go\n- and more...\n\n## Requirements\n\n- nodejs\n\n## Dependencies\n\n- [`express`](https://www.npmjs.com/package/express)\n- [`node-fetch`](https://www.npmjs.com/package/node-fetch)\n\n## Installation\n\nYou can install Treblle for Node via [NPM](https://www.npmjs.com/). Simply run the following command:\n\n```bash\n$ npm install treblle\n```\n\nDon't forget to load the required JS modules in your app.js like so:\n\n```js\nconst express = require(\"express\");\nconst { useTreblle } = require(\"treblle\");\n```\n\n## Getting started\n\nNext, create a FREE account on \u003chttps://treblle.com\u003e to get an API key and Project ID. After you have those simply initialize Treblle in your **app.js** file like so for Express:\n\n```js\nconst app = express();\napp.use(express.json());\n\nuseTreblle(app, {\n  apiKey: \"_YOUR_API_KEY_\",\n  projectId: \"_YOUR_PROJECT_ID_\",\n});\n```\n\nThat's it. Your API requests and responses are now being sent to your Treblle project. Just by adding that line of code you get features like: auto-documentation, real-time request/response monitoring, error tracking and so much more.\n\n### Koa integration\n\nIf you're using koa, then you can enable Treblle like this:\n\n```js\nconst Koa = require(\"koa\");\nconst KoaRouter = require(\"koa-router\");\nconst KoaBody = require(\"koa-body\");\nconst { koaTreblle } = require(\"treblle\");\n\nconst app = new Koa();\nconst router = new KoaRouter();\n\napp.use(\n  koaTreblle({\n    apiKey: \"_YOUR_API_KEY_\",\n    projectId: \"_YOUR_PROJECT_ID_\",\n  })\n);\n```\n\n### Strapi integration\n\nTreblle has support for Strapi as well, to start using it you need to define the middleware first and then enable the middleware.\n\nThis guide is based on the strapi quickstart project, you can create it and follow by running the following command:\n\n```sh\nnpx create-strapi-app my-project --quickstart\n```\n\nFirst define the middleware in `middlewares/treblle/index.js` like this:\n\n```js\nconst { strapiTreblle } = require(\"treblle\");\n\nmodule.exports = (strapi) =\u003e {\n  return {\n    initialize() {\n      strapi.app.use(\n        strapiTreblle({\n          apiKey: \"_YOUR_API_KEY_\",\n          projectId: \"_YOUR_PROJECT_ID_\",\n        })\n      );\n    },\n  };\n};\n```\n\nThen enable the Treblle middleware in `config/middleware.js` like this:\n\n```js\nmodule.exports = {\n  settings: {\n    treblle: {\n      enabled: true,\n    },\n  },\n};\n```\n\n### Cloudflare Workers integration\n\n#### Service workers\n\nTo use external packages (like Treblle) inside your workers you need a bundler (eg. Webpack or Rollup) to gather all dependencies into a single file which can be then deployed to Cloudflare. Read more about it in Cloudflare [webpack](https://developers.cloudflare.com/workers/cli-wrangler/webpack/) \u0026 [configuration](https://developers.cloudflare.com/workers/cli-wrangler/configuration/#service-workers) official documentation, and in an [official example](https://github.com/cloudflare/service-worker-custom-build).\n\nExample - Wrangler's webpack\n\n```toml\n# wrangler.toml\n\n...\ntype = \"webpack\"\nwebpack_config = \"webpack.config.js\"\n\n[build.upload]\nformat = \"service-worker\"\n```\n\n```js\n// webpack.config.js\n\nmodule.exports = {\n  entry: \"./index.js\",\n  target: \"webworker\",\n  mode: \"production\",\n  output: {\n    filename: \"worker.js\",\n  },\n};\n```\n\n```js\n// worker.js\n\nconst { serviceWorkerTreblle } = require(\"treblle\");\n\n// Call this function for initialization, Treblle will attach itself to the 'fetch' event to be able to listen for response\nconst treblle = serviceWorkerTreblle({\n  apiKey: \"_YOUR_API_KEY_\",\n  projectId: \"_YOUR_PROJECT_ID_\",\n  additionalFieldsToMask: ['key1', 'key2'], // Optional\n  showErrors: false, // Optional, defaults to false\n});\n\n// Wrap your 'fetch' handler inside returned Treblle function, so Treblle can listen for unhandled application errors in your code\naddEventListener(\n  \"fetch\",\n  treblle((event) =\u003e {\n    event.respondWith(\n      new Response(\"Hello worker!\", {\n        headers: { \"content-type\": \"text/plain\" },\n      })\n    );\n  })\n);\n```\n\n#### Module workers\n\nSimilar as with Service workers above, you need a bundler to package Treblle SDK together with your application code. Be sure to check out official Cloudflare documentation about [webpack]() \u0026 [modules configuration](https://developers.cloudflare.com/workers/cli-wrangler/configuration/#modules) if you are stuck.\n\nHere is also an official example of a setup with both Modules and CommonJS, using Webpack: [link](https://github.com/cloudflare/modules-webpack-commonjs).\n\nExample\n\n```js\n// worker.js\n\nimport { moduleWorkerTreblle } from \"treblle\";\n\n// Initialize Treblle with this function, and store Treblle wrapper inside a variable\nconst treblle = moduleWorkerTreblle({\n  apiKey: \"_YOUR_API_KEY_\",\n  projectId: \"_YOUR_PROJECT_ID_\",\n  additionalFieldsToMask: ['key1', 'key2'], // Optional\n  showErrors: false, // Optional, defaults to false\n});\n\nexport default {\n  // Wrap your 'fetch' handlers inside Treblle wrapper function to use it\n  fetch: treblle(async (request) =\u003e {\n    return new Response(JSON.stringify({ sample: \"json\" }), {\n      headers: { \"content-type\": \"application/json\" },\n    });\n  }),\n};\n```\n\n**Important Note**\n\nTreblle package (currently) uses some Node native libraries for other integrations, like `os` \u0026 `url`, which are not supported in Cloudflare Workers Runtime. They are not used in this integration, so it is enough to polyfil them with empty modules.\n\n```js\n// webpack.config.js\n\n...\n  resolve: {\n    fallback: {\n      os: false,\n      url: false\n    }\n  }\n...\n```\n\n### NestJS (with Express)\n\n\n```js\n// NestJS's boostrap function\n\nconst app = await NestFactory.create(AppModule);\n\n...\n\nconst expressInstance = app.getHttpAdapter().getInstance();\n\nuseNestTreblle(expressInstance, {\n  apiKey: \"_YOUR_API_KEY_\",\n  projectId: \"_YOUR_PROJECT_ID_\",\n});\n\n...\n```\n\n\n### Running Treblle only in production\n\nIf you want to run Treblle only in production, you can rely on the environment variables, or use a similar approach via config.\n\n```js\nconst app = express();\napp.use(express.json());\n\nif (process.env.NODE_ENV === \"production\") {\n  useTreblle(app, {\n    apiKey: \"_YOUR_API_KEY_\",\n    projectId: \"_YOUR_PROJECT_ID_\",\n  });\n}\n```\n\n### Need to hide additional fields?\n\nIf you want to expand the list of fields you want to hide, you can pass property names you want to hide by using the `additionalFieldsToMask` setting like in the example below.\n\n```js\nuseTreblle(app, {\n  apiKey: \"_YOUR_API_KEY_\",\n  projectId: \"_YOUR_PROJECT_ID_\",\n  additionalFieldsToMask: [\"secretField\", \"highlySensitiveField\"],\n});\n```\n\n### Logging errors\n\nFor easier debugging when sending the data to Treblle errors are visible by default, you can control it via the `showErrors` flag, you can disable the errors with `showErrors` set to `false`:\n\n```js\nuseTreblle(app, {\n  apiKey: \"_YOUR_API_KEY_\",\n  projectId: \"_YOUR_PROJECT_ID_\",\n  showErrors: false,\n});\n```\n\n## Support\n\nIf you have problems of any kind feel free to reach out via \u003chttps://treblle.com\u003e or email vedran@treblle.com and we'll do our best to help you out.\n\n## License\n\nCopyright 2021, Treblle Limited. Licensed under the MIT license:\nhttp://www.opensource.org/licenses/mit-license.php\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreblle%2Ftreblle-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreblle%2Ftreblle-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreblle%2Ftreblle-node/lists"}