{"id":20420325,"url":"https://github.com/deepraining/js-mocker","last_synced_at":"2025-08-19T13:10:26.027Z","repository":{"id":57283361,"uuid":"292827996","full_name":"deepraining/js-mocker","owner":"deepraining","description":"使用 js 文件生成接口模拟数据. Use js files to make mock data.","archived":false,"fork":false,"pushed_at":"2020-09-25T09:07:15.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-10T08:18:04.309Z","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/deepraining.png","metadata":{"files":{"readme":"README.en.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-04T11:13:51.000Z","updated_at":"2020-09-25T09:07:17.000Z","dependencies_parsed_at":"2022-09-20T00:12:10.833Z","dependency_job_id":null,"html_url":"https://github.com/deepraining/js-mocker","commit_stats":null,"previous_names":["senntyou/js-mocker"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fjs-mocker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fjs-mocker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fjs-mocker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/deepraining%2Fjs-mocker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/deepraining","download_url":"https://codeload.github.com/deepraining/js-mocker/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241963773,"owners_count":20049894,"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":"2024-11-15T06:42:28.154Z","updated_at":"2025-03-05T04:26:50.270Z","avatar_url":"https://github.com/deepraining.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# js-mocker\n\n[中文文档](./README.md)\n\nUse js files to make mock data.\n\n## quick start\n\nInstall js-mocker (Only works in local, not in global):\n\n```\nnpm install js-mocker --save-dev\n```\n\nUsage (You can use [npm scripts](https://docs.npmjs.com/misc/scripts) or [npx](https://www.npmjs.com/package/npx) to run this command):\n\n```\njs-mocker [options] \u003cdir\u003e\n```\n\n## options\n\n- `dir`: mapping all files under `dir` directory to api, based on file's path\n- `-p, --port \u003cport\u003e`: Port to use (defaults to 8092)\n\n## used libraries\n\n- [commander.js](https://github.com/tj/commander.js)\n- [browser-sync](https://github.com/BrowserSync/browser-sync)\n\n## How to use js files to generate mock data\n\n`url`: `/api/user/profile?id=1`\n\nFirst try `/api/user/profile.js`:\n\n```\n// export a function\nexport default (req, res) =\u003e {\n  // do everything you want\n};\n\n// or export an object, a string\nexport default {\n  success: true,\n  message: 'ok',\n  data: { ... },\n};\n```\n\nSecond try `/api/user.js`:\n\n```\n// export a function\nexport const profile = (req, res) =\u003e {\n  // do everything you want\n};\n\n// or export an object, a string\nexport const profile = {\n  success: true,\n  message: 'ok',\n  data: { ... },\n}\n```\n\n`req, res` refers to [Node Http](https://nodejs.org/dist/latest-v8.x/docs/api/http.html), and file name should not contain `.` character, or it will be treated as a static file.\n\n### Support dynamic url\n\nIf you need dynamic url, like `/article/{{articleId}}/comment/{{commentId}}`(`/article/1234/comment/5678`), you can use `$d` to replace dynamic ones.\n\nFor example, you can make `/article/$d/comment/$d.js` to proxy all urls.\n\nOnly starts with number(0-9), will be treated as dynamic url. So, `/article/abc` and `/article/a123` are not dynamic urls.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepraining%2Fjs-mocker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepraining%2Fjs-mocker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepraining%2Fjs-mocker/lists"}