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

@avilang/mock-service

v1.1.6

Published

用于开发时 Mock Api 数据

Readme

mock service

  • 简陋的 mock 服务,为了前端开发方便调试后端接口而创建。
  • 应用场景:前端功能开发调试。后端接口未完成情况下,前端可先对接接口,进行开发等场景。
  • 响应数据优先返回本地文件的 mock 数据,若没有寻找到本地 mock 文件时,则代理到真正的后端接口,返回接口的响应数据。
  • 若后端接口已完成或不想返回本地文件的 mock 数据,可把本地 mock 文件删除或把文件名重命名(不符合文件名称规则即可,命名规则见下文)。

mock-service

安装

  • npm i @avilang/mock-service
  • yarn add @avilang/mock-service
  • pnpm add @avilang/mock-service

使用

  • 在项目中安装好依赖后,创建文件如 mock-app.js (见下文示例代码),填好你的配置。
  • 启动 mock 服务 node mock-app.js
  • 使用前你需修改好你前端项目里的相关配置或文件,把 HTTP 请求代理到你的 mock 服务的端口上。如你使用 vite 作为开发工具,可修改 vite.config.js 文件下 server.proxy 的配置
// mock-app.js
let path = require("path");
let mockService = require("@avilang/mock-service");

mockService.start({
  // mock 服务端口
  port: 9000,
  // mock 文件存放目录(绝对路径)
  mock: path.join(__dirname, "./"),
  // 这里配置是你的后端服务API
  // http-proxy options 见 https://github.com/chimurai/http-proxy-middleware#http-proxy-options
  proxy: {
    "/web/*": {
      target: "http://localhost:8080",
    },
    "/apis/*": {
      target: "http://dev.domain.com",
      changeOrigin: true,
    },
  },
});

mock 文件命名规则

  • 例: 请求方法是 POST 请求 URL 为 /apis/order/code,则对应的 mock 文件为 post_apis_order_code.js
  • 规则: 请求方法(英文小写) + _ + 请求 URl("/"符号替换成 "_")
  • 无需考虑请求的参数,把请求 URL 和文件名匹配好即可,因为本地mock响应的数据完全由你定制,与参数无关。

mock 文件示例:

module.exports = {
  // http status code(可不填,则默认为 200)
  httpStatus: 200,
  // 响应内容
  response: {
    code: 2000,
    list: [...]
  }
}

也可以配合如 Mock 等库,构造数据。