{"id":50762307,"url":"https://github.com/devlinduldulao/json-server","last_synced_at":"2026-06-11T11:01:57.673Z","repository":{"id":285565764,"uuid":"958563369","full_name":"devlinduldulao/json-server","owner":"devlinduldulao","description":"Inspired by json-server, this is a local fake server that has CLI commands for delays, route mapping, and a pagination feature.","archived":false,"fork":false,"pushed_at":"2026-02-14T11:56:17.000Z","size":333,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-06-02T23:06:46.198Z","etag":null,"topics":["alternative","json-server","new","replacement"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/@webmasterdevlin/json-server","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/devlinduldulao.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-01T12:01:53.000Z","updated_at":"2026-02-14T11:56:18.000Z","dependencies_parsed_at":null,"dependency_job_id":"b1ca24d2-2315-4c4d-b699-1b18c1598564","html_url":"https://github.com/devlinduldulao/json-server","commit_stats":null,"previous_names":["webmasterdevlin/json-server","devlinduldulao/json-server"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/devlinduldulao/json-server","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlinduldulao%2Fjson-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlinduldulao%2Fjson-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlinduldulao%2Fjson-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlinduldulao%2Fjson-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devlinduldulao","download_url":"https://codeload.github.com/devlinduldulao/json-server/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devlinduldulao%2Fjson-server/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34195117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"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":["alternative","json-server","new","replacement"],"created_at":"2026-06-11T11:01:56.640Z","updated_at":"2026-06-11T11:01:57.667Z","avatar_url":"https://github.com/devlinduldulao.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @webmasterdevlin/json-server\n\n[![npm version](https://img.shields.io/npm/v/@webmasterdevlin/json-server.svg)](https://www.npmjs.com/package/@webmasterdevlin/json-server)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![Build Status](https://github.com/webmasterdevlin/json-server/actions/workflows/ci.yml/badge.svg)](https://github.com/webmasterdevlin/json-server/actions)\n\nA TypeScript implementation of json-server with additional features and comprehensive TypeScript types.\n\n## Features\n\n- **Full TypeScript support** with comprehensive type definitions\n- **RESTful API endpoints** from a JSON file or JavaScript object\n- **API prefix support** - Access all routes with `/api/*` prefix for production-like experience\n- **Configurable routes** with custom route definitions\n- **Multiple package managers** support (npm, yarn, pnpm, bun)\n- **CORS support** with configurable options\n- **Delay simulation** for network latency testing\n- **Read-only mode** for safe demonstrations\n- **Static file serving** for frontend assets\n- **Custom middleware support** for advanced use cases\n- **Deno compatibility** for modern runtime support\n- **Beautiful CLI interface** with color-coded outputs and intuitive feedback\n- **Comprehensive pagination** with flexible query parameters\n- **Advanced filtering** and sorting capabilities\n\n## Installation\n\n### Using npm\n\n```bash\nnpm install @webmasterdevlin/json-server\n```\n\n### Using yarn\n\n```bash\nyarn add @webmasterdevlin/json-server\n```\n\n### Using pnpm\n\n```bash\npnpm add @webmasterdevlin/json-server\n```\n\n### Using bun\n\n```bash\nbun add @webmasterdevlin/json-server\n```\n\n## Quick Start\n\n### CLI Usage\n\nCreate a `db.json` file:\n\n```json\n{\n  \"posts\": [{ \"id\": 1, \"title\": \"json-server\", \"author\": \"webmasterdevlin\" }],\n  \"comments\": [{ \"id\": 1, \"body\": \"some comment\", \"postId\": 1 }],\n  \"profile\": { \"name\": \"webmasterdevlin\" }\n}\n```\n\nStart the JSON Server:\n\n```bash\nnpx json-server db.json\n```\n\nOr with API prefix support (enables `/api/*` routes):\n\n```bash\nnpx json-server db.json --enable-api-prefix\n```\n\nOr use it from your package.json scripts:\n\n```json\n{\n  \"scripts\": {\n    \"mock-api\": \"json-server db.json\",\n    \"mock-api-with-prefix\": \"json-server db.json --enable-api-prefix\"\n  }\n}\n```\n\nNow if you go to http://localhost:3000/posts/1, you'll get:\n\n```json\n{ \"id\": 1, \"title\": \"json-server\", \"author\": \"webmasterdevlin\" }\n```\n\nWith API prefix enabled, you can also access the same data at http://localhost:3000/api/posts/1.\n\n### API Usage\n\n```typescript\nimport { create } from '@webmasterdevlin/json-server';\n\n// Create a server with custom options\nconst server = create({\n  port: 3001,\n  host: 'localhost',\n  delay: 500, // Add 500ms delay to all responses\n});\n\n// Load database from file\nserver.loadDatabase('./db.json');\n\n// Start the server\nserver.start().then(() =\u003e {\n  console.log('Server is running at http://localhost:3001');\n});\n```\n\n### Deno Usage\n\n```typescript\n// Import from URL or local file\nimport { create } from 'npm:@webmasterdevlin/json-server';\n// OR use the mod.ts entry point\n// import { create } from \"./mod.ts\";\n\nconst server = create({\n  port: 8000,\n  host: 'localhost',\n});\n\n// Load database from file\nserver.loadDatabase('./db.json');\n\n// Start the server\nawait server.start();\n```\n\n## Routes\n\nAll HTTP methods are supported:\n\n```\nGET    /posts\nGET    /posts/1\nPOST   /posts\nPUT    /posts/1\nPATCH  /posts/1\nDELETE /posts/1\n```\n\n### Custom Routes\n\nCreate a `routes.json` file:\n\n```json\n{\n  \"/api/*\": \"/$1\",\n  \"/blog/:id\": \"/posts/:id\",\n  \"/blog/:category/:title\": \"/posts?category=:category\u0026title=:title\"\n}\n```\n\nStart the server with custom routes:\n\n```bash\njson-server db.json --routes routes.json\n```\n\nNow you can access your resources with:\n\n```\n/api/posts\n/api/posts/1\n/blog/1\n/blog/javascript/typescript-basics\n```\n\n## Command Line Options\n\n```\nUsage:\n  json-server [options] \u003csource\u003e\n\nOptions:\n  --port, -p         Set port                                  [default: 3000]\n  --host, -H         Set host                          [default: \"localhost\"]\n  --watch, -w        Watch for changes                        [default: false]\n  --routes, -r       Path to routes file                               [string]\n  --middlewares, -m  Path to middlewares files                          [array]\n  --static, -s       Path to static files                               [array]\n  --read-only, --ro  Allow only GET requests                  [default: false]\n  --no-cors, --nc    Disable CORS                             [default: false]\n  --no-gzip, --ng    Disable GZIP compression                 [default: false]\n  --enable-api-prefix, --api  Enable /api/* prefix routes     [default: false]\n  --delay, -d        Add delay to responses (ms)                       [number]\n  --id, -i           Set database id field                     [default: \"id\"]\n  --foreignKeySuffix Set foreign key suffix               [default: \"_id\"]\n  --quiet, -q        Suppress log messages                    [default: false]\n  --help, -h         Show help                                        [boolean]\n  --version, -v      Show version                                     [boolean]\n```\n\n### Example Commands\n\n```bash\n# Basic usage\njson-server db.json\n\n# With API prefix support\njson-server db.json --enable-api-prefix\n\n# Custom port with API prefix\njson-server db.json --port 3001 --api\n\n# With delay and API prefix\njson-server db.json --delay 1000 --enable-api-prefix\n\n# With custom routes and API prefix\njson-server db.json --routes routes.json --api\n\n# Read-only mode with API prefix\njson-server db.json --read-only --enable-api-prefix\n```\n\n## Filtering and Pagination\n\nUse query parameters for filtering:\n\n```\nGET /posts?title=json-server\u0026author=webmasterdevlin\nGET /posts?id=1\u0026id=2\n```\n\nPagination and sorting:\n\n```\nGET /posts?_page=1\u0026_limit=10\nGET /posts?_sort=title\u0026_order=asc\nGET /posts?_sort=title\u0026_order=desc\n```\n\n## API Prefix\n\nThe API prefix feature allows you to access all your resources with an `/api` prefix, making your mock API feel more like a production backend. When enabled, both standard routes and API-prefixed routes work simultaneously.\n\n### Why Use API Prefix?\n\n- **Production-like experience**: Makes your mock API behave like a real backend with `/api` routes\n- **Frontend framework compatibility**: Works seamlessly with frameworks that expect API routes to start with `/api`\n- **Route organization**: Helps differentiate API routes from static file routes\n- **Development consistency**: Matches common backend API patterns\n\n### Using API Prefix with CLI\n\nEnable the API prefix feature using the `--enable-api-prefix` (or `--api` shorthand) flag:\n\n```bash\njson-server db.json --enable-api-prefix\n```\n\n**Both route styles work simultaneously:**\n\n```bash\n# Standard routes (still work)\ncurl http://localhost:3000/posts\ncurl http://localhost:3000/posts/1\ncurl http://localhost:3000/db\n\n# API-prefixed routes (also work)\ncurl http://localhost:3000/api/posts\ncurl http://localhost:3000/api/posts/1\ncurl http://localhost:3000/api/db\n```\n\n### All HTTP Methods Supported\n\nThe API prefix works with all HTTP methods:\n\n```bash\n# GET requests\nGET /api/posts\nGET /api/posts/1\n\n# POST requests\nPOST /api/posts\nContent-Type: application/json\n{\"title\": \"New Post\", \"author\": \"John Doe\"}\n\n# PUT requests\nPUT /api/posts/1\nContent-Type: application/json\n{\"id\": 1, \"title\": \"Updated Post\", \"author\": \"John Doe\"}\n\n# PATCH requests\nPATCH /api/posts/1\nContent-Type: application/json\n{\"title\": \"Partially Updated Post\"}\n\n# DELETE requests\nDELETE /api/posts/1\n```\n\n### Query Parameters and Pagination\n\nAll query parameters work with the API prefix:\n\n```bash\n# Filtering\nGET /api/posts?author=webmasterdevlin\nGET /api/posts?title=json-server\u0026author=webmasterdevlin\n\n# Pagination\nGET /api/posts?_page=1\u0026_limit=10\nGET /api/posts?_page=2\u0026_limit=5\n\n# Sorting\nGET /api/posts?_sort=title\u0026_order=asc\nGET /api/posts?_sort=id\u0026_order=desc\n\n# Pagination endpoint\nGET /api/posts/paginate?_page=1\u0026_limit=10\n```\n\n### Using API Prefix Programmatically\n\n```typescript\nimport { create } from '@webmasterdevlin/json-server';\n\nconst server = create({\n  port: 3000,\n  enableApiPrefix: true, // Enable the API prefix feature\n});\n\nserver.loadDatabase('./db.json');\nserver.start().then(() =\u003e {\n  console.log('Server running with API prefix support');\n  console.log('Access your API at:');\n  console.log('- http://localhost:3000/posts (standard)');\n  console.log('- http://localhost:3000/api/posts (with prefix)');\n});\n```\n\n### Example with Custom Routes\n\nWhen using custom routes with API prefix enabled:\n\n**routes.json:**\n\n```json\n{\n  \"/api/profile\": {\n    \"GET\": \"/users/1\"\n  },\n  \"/api/featured-post\": {\n    \"GET\": \"/posts/1\"\n  },\n  \"/api/users/:id/posts\": {\n    \"GET\": \"/posts?userId=:id\"\n  }\n}\n```\n\n**Start server:**\n\n```bash\njson-server db.json --routes routes.json --enable-api-prefix\n```\n\n**Access routes:**\n\n```bash\ncurl http://localhost:3000/api/profile\ncurl http://localhost:3000/api/featured-post\ncurl http://localhost:3000/api/users/1/posts\n```\n\n## Programmatic Usage\n\n### Basic Usage\n\n```typescript\nimport { create } from '@webmasterdevlin/json-server';\n\n// Database object\nconst data = {\n  posts: [{ id: 1, title: 'json-server', author: 'webmasterdevlin' }],\n  comments: [{ id: 1, body: 'some comment', postId: 1 }],\n};\n\n// Create server\nconst server = create({\n  port: 3000,\n  host: 'localhost',\n  readOnly: false, // Allow all HTTP methods\n  delay: 1000, // Add 1s delay to responses\n  enableApiPrefix: true, // Enable /api/* prefix for all routes\n});\n\n// Create a custom route\nserver.addRoute('/custom-route', 'GET', (req, res) =\u003e {\n  res.json({ message: 'This is a custom route' });\n});\n\n// Start server\nserver.loadDatabase('./db.json');\nserver.start().then(() =\u003e {\n  console.log('JSON Server is running');\n  console.log('Standard routes: http://localhost:3000/posts');\n  console.log('API routes: http://localhost:3000/api/posts');\n});\n```\n\n### Configuration Options\n\n```typescript\ninterface ServerOptions {\n  port: number; // Server port (default: 3000)\n  host: string; // Server host (default: 'localhost')\n  cors: boolean; // Enable CORS (default: true)\n  static: string | string[]; // Static file paths\n  middlewares: RequestHandler[]; // Custom middlewares\n  bodyParser: boolean; // Enable body parsing (default: true)\n  noCors: boolean; // Disable CORS (default: false)\n  noGzip: boolean; // Disable gzip (default: false)\n  delay: number; // Response delay in ms (default: 0)\n  quiet: boolean; // Suppress logs (default: false)\n  readOnly: boolean; // Read-only mode (default: false)\n  enableApiPrefix: boolean; // Enable /api/* routes (default: false)\n}\n```\n\n## Beautiful CLI Experience\n\nOne of the standout features of this implementation is the beautifully styled CLI interface, designed to make your development experience more enjoyable and informative.\n\n### Server Status Display\n\nWhen you start the server, you'll see a beautiful status banner with:\n\n```\n🚀 JSON Server is running\n\n http://localhost:3000 - API Root\n http://localhost:3000/db - Full Database\n\n Read Only: No\n API Prefix: Enabled\n CORS: Enabled\n\n ℹ️ Press Ctrl+C to stop the server\n```\n\n### Color-Coded Messages\n\nAll CLI messages are color-coded for better readability:\n\n- 🟢 Green for success messages\n- 🔵 Blue for informational messages\n- 🟡 Yellow for warnings\n- 🔴 Red for errors\n\n### Visual Feedback for Key Events\n\n```bash\n💾 Database loaded: db.json (3 collections, 20 items)\n🔀 Loaded 4 custom routes from routes.json\n👀 Watching for changes: db.json\n```\n\n### Beautiful Help Display\n\nThe help command (`json-server --help`) provides a well-organized and colorful display of all available options:\n\n```bash\n⚡️ @webmasterdevlin/json-server ⚡️\nA TypeScript-powered REST API mock server\n\nUsage:\njson-server [options] \u003csource\u003e\n\nOptions:\n  --port, -p         Set port                                  [default: 3000]\n  --host, -H         Set host                          [default: \"localhost\"]\n  # ...more options...\n\nExamples:\n  json-server db.json\n  json-server db.json --port 3001\n  # ...more examples...\n```\n\n### Try It Yourself!\n\nExperience the beautiful CLI interface by installing and running json-server:\n\n```bash\nnpm install @webmasterdevlin/json-server\nnpx json-server db.json\n```\n\n## Development\n\n### Prerequisites\n\n- Node.js (v16.0.0 or higher)\n- npm, yarn, pnpm, or bun\n\n### Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/webmasterdevlin/json-server.git\ncd json-server\n\n# Install dependencies\nnpm install\n\n# Run development server\nnpm run dev\n\n# Run tests\nnpm test\n\n# Build for production\nnpm run build\n```\n\n## Real-World Examples\n\n### Frontend Development with API Prefix\n\nWhen developing a React/Vue/Angular application that will eventually connect to a backend API with `/api` routes:\n\n```bash\n# Start json-server with API prefix\njson-server db.json --enable-api-prefix --port 3001\n\n# Your frontend can now make requests to:\n# http://localhost:3001/api/users\n# http://localhost:3001/api/posts\n# http://localhost:3001/api/comments\n```\n\n**Frontend code example:**\n\n```javascript\n// This will work with both your mock server and production API\nconst response = await fetch('/api/users');\nconst users = await response.json();\n```\n\n### Testing Different Network Conditions\n\n```bash\n# Simulate slow network\njson-server db.json --api --delay 2000\n\n# Test with different delays\njson-server db.json --api --delay 500   # 500ms delay\njson-server db.json --api --delay 1500  # 1.5s delay\n```\n\n### Safe Demo Mode\n\n```bash\n# Read-only mode with API prefix for demos\njson-server db.json --api --read-only\n\n# Only GET requests will work, perfect for demonstrations\n```\n\n## Contributing\n\nPlease read our [Contributing Guide](CONTRIBUTING.md) and [Code of Conduct](CODE_OF_CONDUCT.md) before submitting a pull request.\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Acknowledgements\n\nThis project is inspired by the original [json-server](https://github.com/typicode/json-server) by webmasterdevlin, rewritten in TypeScript with additional features and improvements.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlinduldulao%2Fjson-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevlinduldulao%2Fjson-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevlinduldulao%2Fjson-server/lists"}