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

json-node-mock

v1.0.17

Published

极速创建node本地服务器,快速搭建自己的接口(如果懂服务器部署也能上线)

Downloads

2

Readme

json-node-mock

install

npm i json-node-mock

注意事项(matters needing attention)

注意不能在JS框架中使用当前模块(vue,react),因为当前模块插件基于
Node.js进行集成开发的,Node.js是一个基于ChromeV8引擎的JavaScript运行环境,
而js框架只是有简化Dom操作是对浏览器环境依赖 无法使用一些node的内置模块。
所以我们需要准备以下4步:
1.准备一个空文件夹
2.cd 这个空文件夹 执行终端npm i json-node-mock
3.在根目录创建index.js 并且导入模块开始 可以参考下面的(基本使用)
4.在终端使用 node index.js启动项目
(暂时只能这么麻烦的走4步,后面空了会开发成一个独立的node-cli项目一个命令就能解决)

描述(describe)

前端快速搭建一个自己的本地服务器 用json方式定义接口,类似与mock但是比mock更
简单且支持更多数据接收方式。本地快速启动一个node服务器 并且支持数据持久储存
除了支持常规的接口接收数据方式,还支持formData数据传递,但是不支持上传文件
(以后会支持)

基本使用(Basic usage)

使用模块
const jsonNodeMock = require('json-node-mock');
const openApi = [ // 自定义接口
    { method: 'POST', url: '/api/addUser', target: 'userList', type: 'addto' }
]
jsonNodeMock.open(openApi)
// 当您定义完成接口后 启动项目后终端控制台日志会输出您当前定义的接口的
完整路径与上下关系,会展示一个简单的接口文档。

参数配置(dispose)

const jsonNodeMock = require('json-node-mock');
jsonNodeMock(用户自定义接口(array),是否读取内置的案例接口(Boole),自定义端口号(number))

如何去快速定义接口(Define interfaces)

/** 
 * @describe 前端快速搭建一个自己的本地服务器 用json方式定义接口,类似与mock 但是比mock更简单且热更新,支持更多数据接收方式。
 * @param {*} 本地快速启动一个node服务器 并且支持数据持久储存,除了支持常规的接口接收数据方式,还支持formData数据传递,但是不支持上传文件(以后会支持)
 * @param {string => 'POST' | 'DELETE' | 'GET' | 'POST'} method  (必填)定义接口请求方式 
 * @param {string} url (必填)定义接口路径
 * @param {string => 'addto' | 'delete' | 'read' | 'modify'} type (必填)定义当前接口的作用 addto(添加),delete(删除),read(读取),modify(修改)
 * @param {string} pathKey (必填)定义当前接口去某个数据表中 按照这个结构去查找数据并且进行'修改'或'删除'或'读取'
 * @param {string} target (必填)定义当前接口准备对那个数据表进行操作(默认读取db文件下对应的JSON文件名称)
 * @param {*} 另外数据表的json文件不需要您手动创建只需要在定义接口的时候填写target属性添加数据的时候会自动生成文件 就是您对应的json数据表的名称
 */
// 以下为接口案例
const Interface = [
    // 在userList表中添加 用户列表数据
    { method: 'POST', url: '/api/addUser', target: 'userList', type: 'addto' },
    // 获取userList表中用户列表所有数据
    { method: 'GET', url: '/api/userList', target: 'userList', type: 'read' },
    // 获取用户列表数据中每一项 like.two = 旅游的用户数据 "http://192.168.101.102:8888/api/getLike?like.two=旅游"
    { method: 'GET', url: '/api/getLike', target: 'userList', type: 'read', pathKey: 'like.two' },
    // 修改用户 (必填数据id字段)修改的时候和修改的数据字段的属性名需要相同 会直接映射上去
    { method: 'POST', url: '/api/modify', target: 'userList', type: 'modify' },
    //根据id删除userList表中用户指定的某条数据 "http://192.168.101.102:8888/api/deleteUser?id=5953de5d-a1d4-44a6-bf3c-9546057097e2"
    { method: 'GET', url: '/api/deleteUser', target: 'userList', type: 'delete' },
    // 批量删除,删除用户列表中所有的男性 "http://192.168.101.102:8888/api/deleteUser?sex=男"
    { method: 'GET', url: '/api/deleteSex', target: 'userList', type: 'delete', pathKey: 'sex' },
];