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

mock-master

v0.1.1

Published

mock server

Downloads

9

Readme

mock-master

像拼接积木那样管理mock数据的本地mock数据工具。

安装

npm install --save-dev mock-master

使用

使用方式很灵活,我们先看最简单的用法。

简单用法

第一步

在项目根目录创建文件夹,命名为mockFiles。 然后目录中新建一个文件,命名为kitty.js

# 目录结构
├── mockFiles
│   └── kitty.js
// kitty.js
module.exports = () => {
  return {
    message: 'ok',
    code: 200,
    result: {
      name: 'kitty',
      age: 10
    }
  }
}

第二步

创建mock数据拼接管理文件,命名为mockSwitchMap.js。 这个文件用途之后会介绍,它是本工具最重要的元素之一。

# 目录结构
├── mockFiles
│   └── kitty.js
├── mockSwitchMap.js
module.exports = {
  share: [],
  api: []
}

新建mock的node服务启动文件,命名为mockServer.js

# 目录结构
├── mockFiles
│   └── kitty.js
├── mockServer.js
├── mockSwitchMap.js
// mockServer.js
const MockMaster = require('mock-master')
const path = require('path')
const mockSwitchMap = require('./mockSwitchMap.js')
/**
 * config说明
 * @param mockRoot mock文件的根目录
 * @param port mock服务的端口
 * @param mockSwitchMap mock管理列表
 * @param apiPrefix 客户端请求api的前缀,比如'/api/kitty.json',apiPrefix就是'/api'
 * @param apiSuffix 客户端请求api的后缀,比如'/api/kitty.json',apiSuffix就是'.json'
 */
const mock = new MockMaster({
  root: path.join(__dirname, 'mockFiles'),
  port: 7878,
  switchMap: mockSwitchMap,
  apiPrefix: '/api',
  apiSuffix: '.htm'
})
// 启动mock服务
mock.start()

第三步

运行:

node mockServer.js

这样,就可以像简单的mock工具那样使用了。

使用方法进阶

如果这工具只能和普通的mock工具那样,就没存在的意义了。所以我们接下来介绍进阶方式。