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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@unanim/mock-server

v3.0.0

Published

A package to server JSON files and test Post endpoints

Downloads

8

Readme

@unanim/mock-server

A very simple package to serve static mock JSONs and test post payloads and simulate server responses

Installation

# With yarn
yarn add -D @unanim/mock-server
# With pnpm
pnpm add -D @unanim/mock-server

Usage

Add a script to your project's package.json scripts section:

{
  "scripts": {
    ...
    "mock": "mock-server",
    ...
  }
}

Then you can just run:

# With yarn
yarn mock
# With pnpm
pnpm mock

Behavior

Mock-server will spin up a server at the port 8000 (to change the default port see #options).

It will serve any JSON file present in the ~/public/json folder in your project (to change the default path).

GET

Mock-server let you get any JSON available in you static JSON dir.

Example

Assuming you have this files:

/public/json/en/common.json
/public/json/en/page/home.json

This GET endpoints will return matching JSON files

http://localhost/en/common
http://localhost/en/common.json
http://localhost/en/page/home
http://localhost/en/page/home.json

POST

You can post data in the /post/{slug} endpoint and it will:

  • Print in the console the payload (after handling formData and parsing JSON)
  • Return the content in the JSON found at /public/json/post/{slug}.json
  • Optionnaly, delay the response with the delay query param (in seconds, default: 0)
  • Optionnaly, return the status code with the code query param (default: 200 if found)

Example

Assuming you have this file in your project:

/public/json/post/newsletter.json

This POST endpoints will be available:

# POST
http://localhost/post/newsletter
http://localhost/post/newsletter?delay=2
http://localhost/post/newsletter?code=300

Options

Dir (default: public/json)

If your static JSON files are located in a different directory pass the dir argument:

mock-server --mockDir=static/json

Port (default: 8000)

If you wish to serve in a different port pass the port argument

mock-server --port=3000

© Made with love and lots of coffee by Unanim.studio