npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@optio-labs/mock-api

v0.0.7

Published

Creates a mock REST API from JSON files.

Readme

mock-rest-api

Creates a mock REST API from JSON files.

Used to mock dependencies of frontends and backends for testing.

The dataset that is returned by the mock API is called an API fixture and is the same sort of concept as a database fixture.

Usage

You need Node.js installed to use mock-api.

Global usage

Install mock-api globally:

npm install --global @optio-labs/mock-api

Change directory to the project for your mock API.

Run the mock-api server:

mock-api

Local usage

Change directory to the Node.js project for your mock API.

Install mock-api in your project:

npm install --save @optio-labs/mock-api

Run the mock-api server:

mock-api

Creating API fixtures

Create API fixtures under the fixtures directory in your project.

Each subdirectory under fixtures is a named fixture, for example:

  • fixtures
    • first-fixture
      • ...
    • second-fixture
      • ...
    • etc...

Under each fixture are nested subdirectories that create routes in the mock API, for example:

  • first-fixture
    • nested-route
      • deeper-route

Under each route directory create a file response.json to create a mock JSON response for that route. for example:

first-fixture/nested-route/deeper-route/response.json:

{
    "msg": "Hello world!"
}

Loading fixtures

A named fixture is loaded by invoking the mock-api route load-fixture.

You can invoke it your browser, for example to load first-fixture open a browser tab and open http://localhost:3000/load-fixture?name=first-fixture.

Alternatively you can use Postman or VS Code REST Client to invoke that route.

Or for the purposes of automated testing (say, using Jest) you could use something like Axios to invoke the route. That means you can make a helper function like the following to load fixtures before running tests:

import axios from "axios";

//
// Loads a named API fixture.
//
export function loadFixture(fixtureName: string): Promise<void> {
    await axios.get(`http://localhost:3000/load-fixture?name=${fixtureName}`);
}

Command line arguments

Usage:

npx mock-api [options]

Options:

  • --port=<port-number> - Sets the port number used by the mock API's HTTP server.
  • --fixture=<fixture-name> - Loads a default fixture on start up.

Development

Clone this repo.

Install dependencies:

cd mock-api
pnpm install

Run in development mode:

npm run start:dev

Run tests:

npm test

Run in prod mode:

npm run build
npm start