# happymock

> A easy mock server

Latest version **1.0.4** (published 2020-02-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install happymock
pnpm add happymock
yarn add happymock
bun add happymock
```

Provides the command `happymock`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-02-17 |
| First published | 2020-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=10 |
| Dependencies | 6 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | heguichuan |
| Maintainers | heguichuan |
| Keywords | happymock, mock, mockjs, json-server, mockserver, mock-server |

## Links

- npm: https://www.npmjs.com/package/happymock
- Repository: https://github.com/heguichuan/happymock
- Issues: https://github.com/heguichuan/happymock/issues
- npm.io page: https://npm.io/package/happymock

## Dependencies (6)

- [mockjs](https://npm.io/package/mockjs.md) ^1.0.1-beta3
- [nodemon](https://npm.io/package/nodemon.md) ^1.19.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^8.1.0
- [get-port](https://npm.io/package/get-port.md) ^5.1.1
- [commander](https://npm.io/package/commander.md) ^2.20.0
- [json-server](https://npm.io/package/json-server.md) ^0.15.0

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.0.4 (latest) — 2020-02-17
- 1.0.3 — 2020-01-17
- 1.0.2 — 2020-01-17

## README

# happymock

[English Docs](https://github.com/heguichuan/happymock/blob/master/README_EN.md)

一个简单的基于[json-server](https://www.npmjs.com/package/json-server)的数据`mock`服务器，提供`api`接口给前端返回模拟数据。

## 使用

### 本地安装启动

```bash
npm install -D happymock
# 方式1. 根目录直接执行happymock

# 方式2. 结合concurrently
npm install -D concurrently
# package.json的scripts中
"dev-mock": "concurrently \"happymock\" \"npm run dev\""

# 启动带mock服务的本地开发
npm run dev-mock
```

### 全局安装启动

```bash
npm install -g happymock
happymock
# 可以在任意目录执行happymock，默认会在当前目录下创建mock文件夹。
# 你可以在每个项目根目录执行命令，以实现每个项目对应一个各自的mock目录。
# 也可以在一个统一的目录执行命令，这样可以以一个服务供给不同的项目。
```

### 可选配置

`--path`: mock 数据存放目录，默认根目录的`./mock`目录

`--port`: mock 服务器监听的端口，默认`6031`端口

### 模拟接口

在`mock/db/index.js`中写好数据，属性名即为接口路径。

> 也可以在`mock/route/index.js`中rewrite你的路由，**这一步不是必须的**。

支持使用`mockjs`快速生成模拟数据。

---
_Source: https://npm.io/package/happymock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
