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

@findtools/mock-server

v1.1.0

Published

based on express to serve mock data

Downloads

10

Readme

一直觉得 UmiJS 默认支持的 Mock 数据 这个功能挺好用的,那如果项目不是用 UmiJS 创建的呢?所以就想写一个工具来启动 mock 服务。

我的需求

  1. 默认根据 mock 文件夹中文件内容来返回接口数据
  2. 默认接口响应时间为 100 到 300 ms
  3. 默认所有接口都会成功,这样 mock 文件夹中就只用写希望模拟的请求的数据,比如删除啊编辑啊就不用写了,因为这种一般只关心是否成功

大概思路

  1. 使用 Express 来启动一个后端服务,当有请求过来时,就根据 mock 文件夹内容去返回响应数据
  2. 使用 chokidar 来监听 mock 文件夹变动
  3. 由于需要考虑接口路径中带参数的场景,可以用 path-to-regexp 来看路径是否匹配

How to use

After npm i @findtools/mock-server , add a script "mock": "mock-server" to your package.json , and then npm run mock to start the mock server. If you want to see all options, run npm run mock -- --help .

The server default watches mock folder. Following is a mock file example. you can use Mock.js to generate random data.

// mock/user.js
const { mock } = require('mockjs')

module.exports = {
  'GET /api/current-user': (req, res) => {
    res.send(
      mock({
        username: '@string(6,12)',
      })
    )
  },
}

How to add custom response header

You can add a key mock-server in your package.json , following is an example. Besides, other options can be configured in package.json too.

"mock-server": {
  "responseHeader": {
    "Access-Control-Allow-Headers": "content-type,authorization,others-xxx-in-request-header",
    "Access-Control-Expose-Headers": "xxx-in-response-header-need-to-tell-frontend"
  }
}

How to ignore specific files

For example, mock-server -i **/mock/**/*.generated.js will ignore all *.generated.js .