{"id":18518,"library":"lws-mock-response","title":"lws-mock-response","description":"Middleware for adding mock responses to lws (local-web-server). Current stable version is 2.0.0, released under an active maintenance cycle. It enables offline development by simulating API responses when network services are unavailable. Mocks are defined in reusable modules. Key differentiators: tight integration with lws ecosystem, simple class-based mock definitions, and support for various response types (JSON, etc.). Ideal for frontend developers working offline or testing scenarios.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/lwsjs/mock-response","tags":["javascript","lws","lws-middleware","mock","response"],"install":[{"cmd":"npm install lws-mock-response","lang":"bash","label":"npm"},{"cmd":"yarn add lws-mock-response","lang":"bash","label":"yarn"},{"cmd":"pnpm add lws-mock-response","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only as of v2. Use import syntax.","wrong":"const lwsMockResponse = require('lws-mock-response')","symbol":"default","correct":"import lwsMockResponse from 'lws-mock-response'"}],"quickstart":{"code":"// Save as mocks.js\nexport default class MockRivers {\n  mocks () {\n    return {\n      route: '/rivers',\n      responses: [\n        {\n          response: {\n            type: 'json',\n            body: [\n              { name: 'Volga', drainsInto: 'Caspian Sea' },\n              { name: 'Danube', drainsInto: 'Black Sea' },\n              { name: 'Ural', drainsInto: 'Caspian Sea' },\n              { name: 'Dnieper', drainsInto: 'Black Sea' }\n            ]\n          }\n        }\n      ]\n    }\n  }\n}\n\n// Then run: ws --mocks mocks.js\n// curl http://127.0.0.1:8000/rivers","lang":"javascript","description":"Creates a mock response module for lws and runs it with the --mocks CLI option. Responds with JSON data for /rivers endpoint."},"warnings":[{"fix":"Update imports to use ESM syntax (import lwsMockResponse from 'lws-mock-response').","message":"v2.0.0 dropped CommonJS support; all imports must use ESM.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Use import instead of require.","cause":"Using require() to load the package which is ESM-only in v2.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}