{"id":14384737,"url":"https://github.com/ajoelp/mock-json-server","last_synced_at":"2025-04-29T01:30:56.431Z","repository":{"id":19114617,"uuid":"61896617","full_name":"ajoelp/mock-json-server","owner":"ajoelp","description":"A mock web server using a JSON file with live-reload support.","archived":false,"fork":false,"pushed_at":"2023-01-04T15:28:55.000Z","size":869,"stargazers_count":33,"open_issues_count":18,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T12:24:22.938Z","etag":null,"topics":["http","http-server","javascript","json","live-reload","mock-server","node"],"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/ajoelp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-24T16:10:56.000Z","updated_at":"2024-12-19T13:37:34.000Z","dependencies_parsed_at":"2023-01-13T20:10:49.781Z","dependency_job_id":null,"html_url":"https://github.com/ajoelp/mock-json-server","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoelp%2Fmock-json-server","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoelp%2Fmock-json-server/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoelp%2Fmock-json-server/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ajoelp%2Fmock-json-server/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ajoelp","download_url":"https://codeload.github.com/ajoelp/mock-json-server/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251415659,"owners_count":21585869,"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":["http","http-server","javascript","json","live-reload","mock-server","node"],"created_at":"2024-08-28T18:01:37.602Z","updated_at":"2025-04-29T01:30:55.222Z","avatar_url":"https://github.com/ajoelp.png","language":"JavaScript","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"readme":"# Mock Json Server\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n[![Build Status](https://jenkins.joelpodrebarac.me/buildStatus/icon?job=Mock-JSON-Server/master)](https://jenkins.joelpodrebarac.me/job/Mock-JSON-Server/job/master/)\n\nCreate a mock server using a json file.\n\n## Installation\n\nTo install, you need to have NodeJS and NPM installed on your system. Go to [https://nodejs.org/en/](https://nodejs.org/en/), download and install one of the provided versions. Both NodeJS and NPM are included.\n\nInstall the mock-json-server package by running `npm install -g mock-json-server` in your terminal.\n\nUsing **npm v5.6.0 or later**? You can skip global installation and directly run `npx mock-json-server data.json` in a folder containing the below explained `data.json`.\n\n**Thats it!**\n\n## Example\n\nTo run the server run: `mock-json-server data.json` This starts a server on http://localhost:8000/\nyou can change the port by running `mock-json-server data.json --port=3000`\n\n`data.json` contains:\n\n```json\n{\n    \"/home\": {\n        \"get\": {\n            \"data\": [\n                {\"id\":1,\"name\": \"Steve\"}\n            ]\n        },\n        \"post\": {\n            \"data\": [\n                {\"id\":1,\"name\": \"Steve French\"}\n            ]\n        }\n    }\n}\n```\n\nA Get Request to http://localhost:8000/home will return.\n\n```json\n    {\n        \"data\": [\n            {\"id\":1,\"name\": \"Steve\"}\n        ]\n    }\n```\n\nA Post Request to http://localhost:8000/home will return.\n\n```json\n    {\n        \"data\": [\n            {\"id\":1,\"name\": \"Steve French\"}\n        ]\n    }\n```\n\n\n## Docker\n\nMock json server is also a docker image. Run it with the command \n```bash\ndocker run --name mock-json-server -v $(pwd)/test/data.json:/usr/src/app/data.json -p 8000:8000 ajoelpod/mock-json-server\n```\n\n\n### Changing the port\n\nRun the same command as above but with the `PORT` environment variable. Also change the -p to be equal to your new port.\n```bash\ndocker run --name mock-json-server --env PORT=3000 -v $(pwd)/test/data.json:/usr/src/app/data.json -p 3000:3000 ajoelpod/mock-json-server\n```\n\n**or**\n\nJust change the forwared ports\n```bash\ndocker run --name mock-json-server -v $(pwd)/test/data.json:/usr/src/app/data.json -p 3000:8000 ajoelpod/mock-json-server\n```\n\n### Docker Compose\n\nExample.\n```yml\nversion: '3'\nservices:\n  mock-json:\n    image: 'ajoelpod/mock-json-server'\n    volumes:\n      - ./test/data.json:/usr/src/app/data.json\n    ports:\n      - 8000:8000\n```\n\n\n## Running Programmatically\n\n```js\nconst server = require('mock-json-server');\nconst app = server({\n  \"/home\": {\n    \"get\": {\n      \"data\": [{ \"id\": 1, \"name\": \"Steve\" }]\n    },\n    \"post\": {\n      \"data\": [{ \"id\": 1, \"name\": \"Steve French\" }]\n    }\n  },\n  \"/test/:id\": {\n    \"get\": {\n      \"data\": [{ \"id\": 1, \"name\": \"Steve\" }]\n    },\n    \"post\": {\n      \"data\": [{ \"id\": 1, \"name\": \"Steve French\" }]\n    }\n  }\n}, 8000); // Start the server with a JSON object;\n\n\n// Start the server;\napp.start();\n\n// Reload the server with new data;\napp.reload({ test : true });\n\n// Stop the server\napp.stop();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajoelp%2Fmock-json-server","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fajoelp%2Fmock-json-server","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fajoelp%2Fmock-json-server/lists"}