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

json-mocks

v1.2.2

Published

Get a full fake REST API with zero coding in less than 10 seconds.

Readme

Mock API Service

Get a full fake REST API with zero coding in less than 10 seconds.

Being a part of front-end and back-end development teams, many times the back-end/third party APIs are just not ready for integration and testing. To get around that, you can simply dump the mock JSON responses here with the required endpoint to get API endpoints up and running.

Usage

WARNING: An earlier version of the package was using ':' as a separator. Since ':' is not a valid filename character in windows, we had to migrate to a more generic separator which is ' '(space).
We do provide backward compatibility, so even if you are using ':' as a separator, you have nothing to worry about.

How to use

  • Create a JSON file with the name of the endpoint in mocks folder. Place the mock response content in the file. Example creating a file with the name hello.json with the content.

    {
        "message": "Hello World"
    }

    will create an endpoint /hello and return the content in API response.

  • You can also create nested sub-directories inside mocks to generate a nested route.

  • Naming Convention for the files inside mocks folder: <HTTP-METHOD><SPACE><ENDPOINT_NAME>.json
    By default, the HTTP method is assumed to be GET. | Http Method | Endpoint | Filename | | --- | --- | --- | | HTTP-METHOD | /endpoint | method-in-lower-case endpoint.json | | GET | /ping | get ping.json or ping.json | | POST | /user | post user.json | | PUT | /user | put user.json | | DELETE | /user | delete user.json |

    Example:

    A directory structure like this generates the following routes

    mocks
    ├── ping.json
    ├── students
    │   └── teams
    │       ├── alpha.json
    │       ├── beta.json
    │       └── post teams.json
    └── users
        ├── new.json
        └── old.json

    List of all generated routes

    Adding route:  GET /ping
    Adding route:  GET /students/teams/alpha
    Adding route:  GET /students/teams/beta
    Adding route:  POST /students/teams/teams
    Adding route:  GET /users/new
    Adding route:  GET /users/old
  • Run npx json-mocks to start the server.

WARNING:
- Ensure to run the command npx json-mocks at the same level where the mocks folder is created.
DO NOT RUN IT INSIDE THE mocks FOLDER.
- The filenames should be in urlencoded format else the endpoints won't accesible. This essentially means to create an endpoint /data list the filename should be /data%20list.

ENV Variables

  • PORT: Port at which the node server will run. If not specified the server will run at port 8080.
  • SERVICE_NAME: Service prefix of path at which the files will be exposed. Default value is empty string.

    Usecase

    If you want to generate the following routes
    GET /user-service/students/teams/alpha
    GET /user-service/students/teams/beta
    POST /user-service/students/teams/teams
    GET /user-service/users/new
    GET /user-service/users/old
    i.e. prefix user-service to all the end points. Then you can set the value of SERVICE_NAME variable to user-service and have the following folder structure:
    mocks
    ├── students
    │   └── teams
    │       ├── alpha.json
    │       ├── beta.json
    │       └── post teams.json
    └── users
        ├── new.json
        └── old.json

Development

  • Clone the repo.
    Place the mock response JSONs with appropriate filenames inside the mocks folder and start the server. You should be good to go.

    You can run the node server locally or use docker.

    • Docker

      1. Run docker build . -t mock-api to build the docker image.
      2. Run docker run -p 8080:8080 -d mock-api to run the container at 8080 port.
    • Locally

      1. Run npm install.
      2. Run npm start to start the server at 8080 or the specified port in env variables. Hit the /ping route to check the health of the server.
  • Check server logs to get list of all the generated endpoints and any incoming requests. We use morgan to log all the incoming requests.

    Sample logs

    Adding route:  GET /user-service/ping  
    Adding route:  GET /user-service/students/teams/alpha  
    Adding route:  GET /user-service/students/teams/beta  
    Adding route:  POST /user-service/students/teams/teams  
    Adding route:  GET /user-service/users/new  
    Adding route:  GET /user-service/users/old  
    Server is running on PORT 8080  
    ::1 - GET /user-service/ping HTTP/1.1 200 18 - 4.575 ms  
    ::1 - GET /user-service/users/old HTTP/1.1 200 62 - 1.624 ms