{"id":18064573,"url":"https://github.com/rn0x/fileservex","last_synced_at":"2026-05-08T13:34:39.199Z","repository":{"id":253079851,"uuid":"842397561","full_name":"rn0x/FileServeX","owner":"rn0x","description":"FileServeX is a Node.js application for serving files through an Express API, including support for different file types and dynamic file paths.","archived":false,"fork":false,"pushed_at":"2024-08-18T04:24:08.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-02T15:42:45.113Z","etag":null,"topics":["api","api-server","express","file","file-serving","files","files-server","fileservex","node","server"],"latest_commit_sha":null,"homepage":"","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/rn0x.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":"2024-08-14T09:12:33.000Z","updated_at":"2024-08-18T04:24:11.000Z","dependencies_parsed_at":"2024-08-18T05:27:08.011Z","dependency_job_id":"cc860891-406e-4b87-b5cd-588955f46e08","html_url":"https://github.com/rn0x/FileServeX","commit_stats":null,"previous_names":["rn0x/fileservex"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rn0x%2FFileServeX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rn0x%2FFileServeX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rn0x%2FFileServeX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rn0x%2FFileServeX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rn0x","download_url":"https://codeload.github.com/rn0x/FileServeX/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247345842,"owners_count":20924102,"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-server","express","file","file-serving","files","files-server","fileservex","node","server"],"created_at":"2024-10-31T06:06:48.944Z","updated_at":"2026-05-08T13:34:34.173Z","avatar_url":"https://github.com/rn0x.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FileServeX\n\n![screencapture-home-i8x-net-2024-08-16-04_46_04](https://github.com/user-attachments/assets/5150ae22-6061-4bb5-aa60-6afba9f577f3)\n\n## Description\n\nThis project is a file server API built with Node.js and Express. The server provides endpoints for serving files and their metadata from the `files` directory. It supports retrieving both the file content and file metadata in JSON format. The server dynamically loads either CommonJS or ES modules based on the environment variable `MODULE_TYPE`.\n\n## Features\n\n- Serves files from the `files` directory.\n- Provides file metadata through `/api/files/*`.\n- Supports JSON and other file types.\n- Dynamically loads either CommonJS or ES modules based on environment configuration.\n- Handles undefined routes and internal server errors gracefully.\n- Automatically creates the `files` directory if it doesn't exist.\n\n## Directory Structure\n\n```plaintext\n.\n├── files/                   # Directory to store files, created automatically if missing\n├── src/                     # Source files directory\n│   ├── routes/              # Express routes\n│   │   ├── fileMetadataRoutes.js  # Route for serving file metadata as JSON\n│   │   └── fileServeRoutes.js     # Route for serving files\n│   ├── utils/               # Utility functions\n│   │   └── fileUtils.js     # File utility functions for handling file retrieval\n│   └── index.js             # Main Express app file\n├── commonjs.js              # CommonJS module file (if MODULE_TYPE is 'commonjs')\n├── module.mjs              # ES Module file (if MODULE_TYPE is 'module')\n├── server.js                # Entry point of the application, handles module loading\n└── README.md                # Project documentation\n```\n\n## Installation\n\n1. **Clone the repository:**\n\n   ```sh\n   git clone https://github.com/rn0x/fileservex\n   cd fileservex\n   ```\n\n2. **Install dependencies:**\n\n   ```sh\n   npm install\n   ```\n\n3. **Create a `.env` file** in the root directory and specify the port and module type:\n\n   ```\n   PORT=7000\n   MODULE_TYPE=commonjs\n   ```\n\n4. **Run the server:**\n   ```sh\n   npm start\n   ```\n\n## Usage\n\n- **Retrieve File Metadata:**\n\n  - Endpoint: `/api/files/*`\n  - Method: `GET`\n  - Example: `GET http://localhost:7000/api/files/example.json`\n\n  This endpoint retrieves metadata for files from the `files` directory. If the requested file exists, the server responds with JSON metadata, including size, modification date, and a URL for downloading the file.\n\n- **Retrieve a File:**\n\n  - Endpoint: `/files/*`\n  - Method: `GET`\n  - Example: `GET http://localhost:7000/files/example.json`\n\n  This endpoint serves the actual file content from the `files` directory. If the file has a `.json` extension, it will be returned as JSON. For other file types, the raw file content will be sent.\n\n- **Root Endpoint:**\n\n  - Endpoint: `/`\n  - Method: `GET`\n  - Example: `GET http://localhost:7000/`\n\n  The root endpoint serves the `index.html` file located in the project root directory.\n\n## Error Handling\n\n- **Route Not Found:**\n  If a request is made to an undefined route, the server returns a `404` status with an error message.\n\n- **Internal Server Errors:**\n  Any unhandled errors are caught by the error handling middleware, which logs the error and returns a `500` status with a generic error message.\n\n## Environment Variables\n\n- **MODULE_TYPE:** Determines whether to use CommonJS (`commonjs`) or ES modules (`module`). Defaults to `commonjs` if not specified.\n- **PORT:** Specifies the port on which the server runs. Defaults to `7000` if not specified.\n\n## Example .env File\n\n```\nPORT=7000\nMODULE_TYPE=commonjs\n```\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## Contribution\n\nFeel free to contribute by submitting a pull request or opening an issue. Please follow the code of conduct and ensure your code adheres to the project's coding standards.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frn0x%2Ffileservex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frn0x%2Ffileservex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frn0x%2Ffileservex/lists"}