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

api-sniff-mock

v0.0.4

Published

a local and remote api sniff-mock middleware

Readme

api-sniff-mock 本地/远程mock接口嗅探及模拟工具

一个node中间件,服务于前端开发过程接口mock需要,支持本地Mock和远程Mock接口请求的方式,亦可混合使用,便于集成工程化自动化,即擦即用。

安装

npm i -D api-sniff-mock

快速上手


const apiSniffMock = require('api-sniff-mock');
const mw = apiSniffMock({
        remote: 'http://www.xxx.com', // 远程mock api请求url前缀
        root:  path.resolve(__dirname, './apiMock'), // 本地mock api所在根路径
        route: '/apiMock',  // 目标拦截路由,以对请求地址做检验,命中后开启mock功能。 参数接受字段串、正则、函数
        useVirtualRoute: true, // 是否使用虚拟route,如果值判断为真,则实际接口请求路径中不包含已配置的route参数值
        silence: true // 是否启用静默模式,如果为否会输入调试信息
    });


// browserSync

browserSync.init({
  server: {
    baseDir: "./",
     middleware: mw
}
});


// ebpack-dev-server

 devServer: {
    before(app) {
      if(process.env.npm_config_proxydev) {
        return;
      } else {
        app.use(mw)
      }
    }

    ...
 }   

本地mock示例

以模拟/api/login接口为例,配置同上述配置,本地mock数据文件路径为: /apiMock/api/login.js


// req 为request对象


var curTime = +new Date(),
start = curTime - 1000 * 90,
end = curTime + 1000 * 60;

var bodyData = req.bodyData; // post请求体数据对象
var queryData = req.queryData; // query数据对象
var pageSize = bodyData.pageSize || 10;
var pageNo = bodyData.pageNo || 1;

// 模块接口延迟
function sleep(numberMillis) { 
  var now = new Date(); 
  var exitTime = now.getTime() + numberMillis; 
  while (true) { 
    now = new Date(); 
    if (now.getTime() > exitTime) {
      doNext();
      return; 
    }
  } 
}

sleep(3000); // 延迟3秒后响应

function doNext(){

  // 响应请求
  callback({
     "code": bodyData.code,
     "password": bodyData.password,
     "sid": bodyData.sid
  });
}