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

http-mockjs

v4.6.2

Published

Simple, independent tools for request mock and proxy

Downloads

18

Readme

http-mockjsnpm

The core feature package of http-mockjs

A tool for the local mock interface.

It has the following features:

  1. Perform the mock mapping relationship through the httpmock field in the package.json , or configuration file .httpmockrc.
  2. Support mockjs syntax, flexible configuration of dynamic mock return value;
  3. Identify express-style urls based on path-to-regexp

Usage

Configuration

Take a configuration file .httpmockrc as an example:

{
    "mockFileName":"mymocks",
    "responseHeaders": {
        "Content-Type": "application/json",
        "X-Proxy-By": "http-mockjs"
    },
    "routes":{
        "GET /j/getSomeData.json":
        {
            "path": "/api/get.json"
        },
        "POST /p/postData.do":
        {
            "path": "/api/post.json"
        },
        "GET /user/:id":{
            "path": "/api/user.json"
        },
        "GET /users/:id+":{
            "path": "/api/info.json"
        }
    }
}

Return the file content demo as follows, you can use the mockjs style:

{
    "code":0,
    "message":"success",
    "result":{
        "content":true,
        "name":"brizer123",
        "domain":"@domain()",
        "otherUrl":"@url()",
        "desciption":"@cparagraph(1, 3)",
        "date":"@date('yyyy-MM-dd')"
    }
}

mockFileName

The root path where the mock file is stored, default is mocks

routes

Mapping management of the corresponding interface

port

Which port to start mock server, default is 8009

working with webpack-dev-server

Config in devServer.before

  devServer:{
    before:(app)=>{
      mocker(app)
    }
  }

demo

working with express

set app into mocker:

const app = express();
const {mocker} = require('http-mockjs')

mocker(app)

app.listen(8002)

working with command line tools such as http-server

Proxy the request to the proxy server started by httpmock through the proxy http-server.

  "scripts": {
    "serve": "http-server -p 8008 -P http://localhost:8001/",
    "mock": "httpmock 8001"
  }

demo