{"id":18492741,"url":"https://github.com/bhumijgupta/erel","last_synced_at":"2025-04-08T21:31:30.424Z","repository":{"id":42719513,"uuid":"287060819","full_name":"bhumijgupta/erel","owner":"bhumijgupta","description":"Express-route-exit-log (EREL) is an customisable express middleware package to log useful request insights when route execution finishes","archived":false,"fork":false,"pushed_at":"2023-03-05T10:34:21.000Z","size":278,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-18T07:09:40.259Z","etag":null,"topics":["express","express-js","express-logger","express-middleware","express-routes","logger","logger-middleware","logging","middleware"],"latest_commit_sha":null,"homepage":"","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/bhumijgupta.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-08-12T16:18:24.000Z","updated_at":"2023-03-04T10:10:55.000Z","dependencies_parsed_at":"2024-08-23T05:03:54.227Z","dependency_job_id":null,"html_url":"https://github.com/bhumijgupta/erel","commit_stats":{"total_commits":25,"total_committers":2,"mean_commits":12.5,"dds":"0.040000000000000036","last_synced_commit":"b2d081b1af90161f04ba33ceac169ad61b5d16d2"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Ferel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Ferel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Ferel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bhumijgupta%2Ferel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bhumijgupta","download_url":"https://codeload.github.com/bhumijgupta/erel/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247931398,"owners_count":21020228,"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","express-logger","express-middleware","express-routes","logger","logger-middleware","logging","middleware"],"created_at":"2024-11-06T13:10:41.547Z","updated_at":"2025-04-08T21:31:25.401Z","avatar_url":"https://github.com/bhumijgupta.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e \n\u003ch1\u003eEREL\u003c/h1\u003e\n\u003cimg src=\"https://github.com/bhumijgupta/erel/workflows/NPM%20Publish/badge.svg\" alt=\"NPM Publish\"\u003e \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/erel\"\u003e \u003cimg alt=\"npm bundle size\" src=\"https://img.shields.io/bundlephobia/min/erel?color=green\"\u003e \u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/l/erel\"\u003e \u003cimg alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/bhumijgupta/erel?style=plastic\"\u003e\u003cbr/\u003e\nExpress-route-exit-log (EREL) is a customisable express middleware package to log useful request insights when route execution finishes.\n\u003c/div\u003e\n\n#### Features\n\n- Written in TypeScript\n- Included types for intellisense in IDE\n- Supports both CJS and ESM modules\n- Small package and easy to set up\n- Support for custom logging solution\n- Provides route insights like IP address, status code, execution time. etc\n\n## Install\n\n```bash\n# NPM\nnpm i erel --save\n\n# Yarn\nyarn add erel\n```\n\n## Screenshot\n\nLogging route insights using custom logger and EREL  \n![Demo screenshot](https://github.com/bhumijgupta/erel/raw/master/assets/screenshot.png)\n\n## Usage\n\n1. For JavaScript\n\n```javascript\nconst express = require('express');\nconst app = express();\n\n// Import exitLog from erel\nconst { exitLog } = require('erel');\n\n// Use your custom logging solution (optional but preferred)\nconst customLogger = (data, req, res) =\u003e {\n  Logger.info(\n    `${data.timestamp} - ${data.ip} - ${data.method} - ${data.route} - ${data.statusCode} - ${data.responseTime}`,\n  );\n};\nexitLog.setLogger(customLogger);\n\n// Configure express app to use the middleware\napp.use(exitLog.middleware);\n```\n\n2. For TypeScript\n\n```typescript\nimport * as express from 'express';\nconst app = express();\n\n// import exitLog and LoggerCallback from erel\nimport { exitLog, LoggerCallback } from 'erel';\n\n// Use your custom logging solution (optional but preferred)\nconst customLogger: LoggerCallback = (data, req, res) =\u003e {\n  Logger.info(\n    `${data.timestamp} - ${data.ip} - ${data.method} - ${data.route} - ${data.statusCode} - ${data.responseTime}`,\n  );\n};\nexitLog.setLogger(customLogger);\n\n// Configure express app to use the middleware\napp.use(exitLog.middleware);\n```\n\n## API Reference\n\n### exitLog\n\n- #### `exitLog.setLogger`\n\n`setLogger` method can be used to set your custom Logging function which will be called along with the request insights.\nIt accepts a logger function as argument which implements the `LoggerCallback` interface. See [LoggerCallback](#LoggerCallback) for more details.\n\n```typescript\n// Example\n\nimport { exitLog } from 'erel';\n// req and res is also passed to log custom objects, like req.userId\nexitLog.setLogger((data, req, res) =\u003e {\n  Logger.log(`${data.timestamp} - ${req.userId} - ${data.ip} - ${data.statusCode}`);\n});\n```\n\n- #### `exitLog.middleware`\n\n`middleware` is the inbuilt middleware function to be configured with express to use. This middleware will call the custom Logger function (if set using `exitLog.setLogger`), otherwise the default Logger.\n\n```typescript\n// Example\nimport * as express from 'express';\nimport { exitLog } from 'erel';\nconst app = express();\napp.use(exitLog.middleware);\n```\n\n### LoggerCallback\n\n`LoggerCallback` is an interface for the custom logger function to be used.\n\n```typescript\ntype LoggerCallback = (data: exitData, req?: Request, res?: Response) =\u003e void;\n// data -\u003e request insights\n// req -\u003e express request object\n// res -\u003e express response object\n```\n\n`data` contains the following properties\n| Property | Type | Description |\n|--------------|:-------------------:|:---------------------------------------------------:|\n| `rawEnterDate` | `Date` | Date when request entered the route |\n| `rawExitDate` | `Date` | Date when request finished route execution |\n| `timestamp` | `string` | Timestamp when route finished execution |\n| `statusCode` | `number` | Response status code |\n| `route` | `string` | Route accessed |\n| `ip` | `string \\| undefined` | IP address of the request |\n| `responseTime` | `number` | Time taken in millisecond to finish route execution |\n| `method` | `string` | Request method to access the endpoint |\n\n#### Need more insights?\n\nConsider opening a feature request [here](https://github.com/bhumijgupta/erel/issues/new).\n\n### License\n\n\u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/l/erel\"\u003e\n\n## Build with ♡ by\n\n### Bhumij Gupta\n\n\u003cimg src=\"https://avatars.githubusercontent.com/bhumijgupta?size=200\" alt=\"Bhumij profile picture\"\u003e\n\n![GitHub followers](https://img.shields.io/github/followers/bhumijgupta?label=Follow\u0026style=social) [![LinkedIn](https://img.shields.io/static/v1.svg?label=connect\u0026message=@bhumijgupta\u0026color=success\u0026logo=linkedin\u0026style=flat\u0026logoColor=white)](https://www.linkedin.com/in/bhumijgupta/) ![Twitter Follow](https://img.shields.io/twitter/follow/bhumijgupta?style=social)\n\n---\n\n```javascript\nif (repo.isAwesome || repo.isHelpful) {\n  StarRepo();\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhumijgupta%2Ferel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbhumijgupta%2Ferel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbhumijgupta%2Ferel/lists"}