{"id":27966051,"url":"https://github.com/techstark/express-mock-api-middleware","last_synced_at":"2025-07-25T07:38:38.953Z","repository":{"id":34246085,"uuid":"173589820","full_name":"TechStark/express-mock-api-middleware","owner":"TechStark","description":"Express middleware for mocking restful APIs","archived":false,"fork":false,"pushed_at":"2023-01-07T05:20:34.000Z","size":736,"stargazers_count":4,"open_issues_count":5,"forks_count":1,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-07-14T11:06:05.842Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TechStark.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-03-03T15:03:23.000Z","updated_at":"2023-11-03T12:21:55.000Z","dependencies_parsed_at":"2023-01-15T05:37:55.587Z","dependency_job_id":null,"html_url":"https://github.com/TechStark/express-mock-api-middleware","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/TechStark/express-mock-api-middleware","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechStark%2Fexpress-mock-api-middleware","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechStark%2Fexpress-mock-api-middleware/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechStark%2Fexpress-mock-api-middleware/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechStark%2Fexpress-mock-api-middleware/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TechStark","download_url":"https://codeload.github.com/TechStark/express-mock-api-middleware/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TechStark%2Fexpress-mock-api-middleware/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266974537,"owners_count":24014928,"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","status":"online","status_checked_at":"2025-07-25T02:00:09.625Z","response_time":70,"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":[],"created_at":"2025-05-07T20:16:17.729Z","updated_at":"2025-07-25T07:38:38.932Z","avatar_url":"https://github.com/TechStark.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# express-mock-api-middleware\nExpress middleware for mocking restful APIs\n\n![express-mock-api-middleware CI](https://github.com/TechStark/express-mock-api-middleware/workflows/express-mock-api-middleware%20CI/badge.svg)\n\n# Install\n```\nnpm install --save-dev express-mock-api-middleware\n```\nor\n```\nyarn add --dev express-mock-api-middleware\n```\n\n# Usage\n\n## Express\nIn your `server.js`, add the following code\n```\nconst path = require('path');\nconst express = require('express');\n\nconst app = express();\nconst mockApiMiddleware = require('express-mock-api-middleware')(\n  path.resolve(__dirname, 'mock'),\n  { ignore: ['asm.js'] }\n);\napp.use('/', mockApiMiddleware);\n\nconst host = 'localhost';\nconst port = 4000;\n\napp.listen(port, host, error =\u003e {\n  if (error) {\n    console.error(error);\n    return;\n  }\n  console.info(`http://${host}:${port}`);\n});\n```\n`path.resolve(__dirname, 'mock')` is the folder where mock API files are.\n`{ ignore: ['asm.js'] }` is the options for more flexible glob. (See how to use `ignore` in [options](https://github.com/isaacs/node-glob#options))\n\n## Mock files\nFor example in file `/mock/user.js`, you can have content\n```\n// you can write your own mock logic here\nmodule.exports = {\n  'GET /api/user/info': {\n    id: 101,\n    userName: 'bob',\n    email: 'bob@gmail.com',\n    firstName: 'Bob',\n    lastName: 'Bushee',\n  },\n\n  'POST /api/user/login': (req, res) =\u003e {\n    const { userName, password } = req.body;\n    if (userName === 'bob' \u0026\u0026 password === 'password') {\n      res.send({\n        success: true,\n      });\n    } else {\n      res.send({\n        success: false,\n      });\n    }\n  },\n\n  'GET /api/product/:id': (req, res) =\u003e {\n    const { id } = req.params;\n    res.sendFile(path.join(__dirname, `products/${id}.json`));\n  }\n};\n```\nThen you can access the mock API from `http://localhost:4000/api/user/info`.\n\n## Show debug log\nSet the `DEBUG` environment variable\n```\nDEBUG=mock-api\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechstark%2Fexpress-mock-api-middleware","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechstark%2Fexpress-mock-api-middleware","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechstark%2Fexpress-mock-api-middleware/lists"}