Data Mocks Server is a JavaScript/TypeScript library designed for creating a standalone mock HTTP server, contrasting with client-side libraries that intercept `fetch` or `XHR` requests. It's built on Express, allowing developers to define API responses and scenarios through configuration rather than network interception. The library is currently at version 10.0.2, with its latest update in July 2024, indicating active maintenance. Releases are not on a fixed schedule but appear when features or bug fixes are available, with significant gaps between major versions like v9 to v10. Key differentiators include its server-first approach, a built-in UI for dynamic scenario switching at runtime, and comprehensive TypeScript support. It's particularly useful for end-to-end testing, local development, and showcasing features without relying on a real backend.
npm install data-mocks-serverVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a mock server with default HTTP GET endpoints for users and products, including dynamic responses and delays. It also defines two scenarios ('emptyUsers' and 'errorProduct') that can be activated via the built-in UI to override default behaviors, and customizes the port and UI path.
Review the new `Response` API documentation and update your mock definitions accordingly. The `response` property may now accept a function or a more structured object for status, headers, and data.
Always consult the changelog for major version bumps. If migrating from pre-9.3.2, ensure all response configurations are updated to the new format.
Always use the latest stable patch release (e.g., `^10.0.0`) to ensure you're on the most recent, non-deprecated version. If you specifically installed `9.3.2`, consider upgrading.
Configure a different `port` or `uiPath` in the `options` object when calling `run`. For example, `{ options: { port: 4000, uiPath: '/_mocks' } }`.Specify a different port in the `options` object: `run({ ..., options: { port: 4000 } })`.Update your mock `response` definitions. Instead of `{ data: {...} }`, use `{ status: 200, data: {...}, headers: {...} }` or return an object with these properties from a response function.Ensure you are using `import { run } from 'data-mocks-server';` in ESM contexts. If using CommonJS, `const { run } = require('data-mocks-server');`. For TypeScript, verify your `tsconfig.json` includes `"moduleResolution": "NodeNext"` or `"Node"` and `"esModuleInterop": true`.No dependency data recorded yet.