{"id":24026797,"url":"https://github.com/systemsoftware/backend","last_synced_at":"2025-08-14T19:23:28.267Z","repository":{"id":271452435,"uuid":"913106150","full_name":"systemsoftware/backend","owner":"systemsoftware","description":"This repository contains a boilerplate for creating a secure and scalable Express.js server. It includes features like rate limiting, Firebase token verification, and advanced logging.","archived":false,"fork":false,"pushed_at":"2025-01-07T20:13:29.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-07T21:22:55.101Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/systemsoftware.png","metadata":{"files":{"readme":"README.LOGGING.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":"2025-01-07T03:35:24.000Z","updated_at":"2025-01-07T20:13:32.000Z","dependencies_parsed_at":"2025-01-07T21:22:59.572Z","dependency_job_id":"6058ed4b-1303-4e36-9a0e-ad1ceeeff3e5","html_url":"https://github.com/systemsoftware/backend","commit_stats":null,"previous_names":["systemsoftware/backend"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemsoftware%2Fbackend","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemsoftware%2Fbackend/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemsoftware%2Fbackend/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/systemsoftware%2Fbackend/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/systemsoftware","download_url":"https://codeload.github.com/systemsoftware/backend/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240783137,"owners_count":19856780,"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":[],"created_at":"2025-01-08T16:50:25.678Z","updated_at":"2025-02-26T03:17:39.153Z","avatar_url":"https://github.com/systemsoftware.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Logging Utility Documentation\n\nThis utility module provides a collection of reusable functions for standardized API responses and logging in Node.js applications. The functions include error handling, API responses, and colored console logging.\n\n---\n\n## **API Response Handlers**\n\n### `APIError`\n\n**Description:** Generates a standardized API error response.\n\n**Usage:**\n\n```javascript\nAPIError(payload={msg, code, res});\n```\n\n**Parameters:**\n\n- `payload.msg` (optional): Custom error message. Defaults to `'An error occurred'`.\n- `payload.code` (optional): HTTP status code. Defaults to `500`.\n- `payload.res` (optional): Express response object. If provided, sends the error response directly to the client.\n\n**Returns:**\n\n- If `payload.res` is provided, sends the error response directly to the client.\n- If `payload.res` is not provided, returns a JSON object:\n  ```json\n  {\n    \"error\": \"Error message\",\n    \"status\": 500\n  }\n  ```\n\n**Example:**\n\n```javascript\nAPIError({ msg: \"Not Found\", code: 404, res: response });\n```\n\n---\n\n### `APIResponse`\n\n**Description:** Generates a standardized API success response.\n\n**Usage:**\n\n```javascript\nAPIResponse(payload={msg, data, code, res});\n```\n\n**Parameters:**\n\n- `payload.msg` (optional): Custom success message. Defaults to `'Success'`.\n- `payload.data` (optional): Data to include in the response. Defaults to `null`.\n- `payload.code` (optional): HTTP status code. Defaults to `200`.\n- `payload.res` (optional): Express response object. If provided, sends the success response directly to the client.\n\n**Returns:**\n\n- If `payload.res` is provided, sends the success response directly to the client.\n- If `payload.res` is not provided, returns a JSON object:\n  ```json\n  {\n    \"message\": \"Success\",\n    \"data\": null,\n    \"status\": 200\n  }\n  ```\n\n**Example:**\n\n```javascript\nAPIResponse({ msg: \"Data retrieved successfully\", data: userData, res: response });\n```\n\n---\n\n### `APIResponseError`\n\n**Description:** Generates an API response for errors that include additional data.\n\n**Usage:**\n\n```javascript\nAPIResponseError(payload={msg, data, code, res});\n```\n\n**Parameters:**\n\n- `payload.msg` (optional): Custom error message. Defaults to `'An error occurred'`.\n- `payload.data` (optional): Data to include in the error response. Defaults to `null`.\n- `payload.code` (optional): HTTP status code. Defaults to `500`.\n- `payload.res` (optional): Express response object. If provided, sends the error response directly to the client.\n\n**Returns:**\n\n- If `payload.res` is provided, sends the error response directly to the client.\n- If `payload.res` is not provided, returns a JSON object:\n  ```json\n  {\n    \"error\": \"Error message\",\n    \"data\": null,\n    \"status\": 500\n  }\n  ```\n\n**Example:**\n\n```javascript\nAPIResponseError({ msg: \"Invalid data\", data: validationErrors, res: response });\n```\n\n---\n\n## **Logging Functions**\n\nThese functions add color-coded logs to the console for better readability.\n\nFirst, import the functions into your project:\n\n```javascript\nconst { success, error, info, warn, special } = require('./logs');\n```\n\n### `success`\n\n**Description:** Logs a success message in green.\n\n**Usage:**\n\n```javascript\nsuccess(...msgs);\n```\n\n**Parameters:**\n\n- `...msgs`: Messages to log. Multiple arguments are concatenated into a single string.\n\n**Example:**\n\n```javascript\nsuccess(\"Server started successfully on port\", port);\n```\n\n---\n\n### `error`\n\n**Description:** Logs an error message in red.\n\n**Usage:**\n\n```javascript\nerror(...msgs);\n```\n\n**Parameters:**\n\n- `...msgs`: Messages to log. Multiple arguments are concatenated into a single string.\n\n**Example:**\n\n```javascript\nerror(\"Failed to connect to database\");\n```\n\n---\n\n### `info`\n\n**Description:** Logs an informational message in blue.\n\n**Usage:**\n\n```javascript\ninfo(...msgs);\n```\n\n**Parameters:**\n\n- `...msgs`: Messages to log. Multiple arguments are concatenated into a single string.\n\n**Example:**\n\n```javascript\ninfo(\"New user registered:\", username);\n```\n\n---\n\n### `warn`\n\n**Description:** Logs a warning message in yellow.\n\n**Usage:**\n\n```javascript\nwarn(...msgs);\n```\n\n**Parameters:**\n\n- `...msgs`: Messages to log. Multiple arguments are concatenated into a single string.\n\n**Example:**\n\n```javascript\nwarn(\"Disk space running low\");\n```\n\n---\n\n### `special`\n\n**Description:** Logs a custom message in magenta.\n\n**Usage:**\n\n```javascript\nspecial(...msgs);\n```\n\n**Parameters:**\n\n- `...msgs`: Messages to log. Multiple arguments are concatenated into a single string.\n\n**Example:**\n\n```javascript\nspecial(\"Special debug message for admins\");\n```\n\n---\n\n\n### Original Console Methods\n\nSince index.js overwrites the original `console` methods, such as `console.error`, `console.info`, and `console.warn`, this file also preserves them via `original.error`, `original.info`, and `original.warn`, respectively. This allows you to use the default console behavior if needed.\n\n**Example:**\n```javascript\nconst { error, original } = require('./logs');\n\n// Use error logging\nerror(\"This is an error message\");\n\n// Use original console error\noriginal.error(\"This is a default error message\");\n```\n\n\n---\n\n## **Summary**\n\nThis module simplifies response handling and logging in Node.js applications. It ensures consistent API responses and provides visually distinct logs for easier debugging. Import and use the functions in your project as needed.\n\n**Example Integration:**\n\n```javascript\nconst { APIResponse, APIError, success, error } = require('./logs');\n\napp.get('/api', (req, res) =\u003e {\n    try {\n        // Successful response\n        APIResponse({ msg: \"Hello, world!\", data: { greeting: \"Hello\" }, res });\n        success(\"API endpoint /api was called\");\n    } catch (err) {\n        // Error response\n        APIError({ msg: \"Something went wrong\", code: 500, res });\n        error(\"Error at /api:\", err.message);\n    }\n});\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemsoftware%2Fbackend","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsystemsoftware%2Fbackend","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsystemsoftware%2Fbackend/lists"}