node-http-mock

0.5.2 • Public • Published

node-http-mock

A HTTP mock server for node.js

Usage

Install it:

npm install node-http-mock -g

And run this command in your termial:

mock -t [api host] -p [local port] -c [config file]

Config File

You can use config file instead of command line options:

// mock.config.js
module.exports = {
  port: 5000,
  verbose: true,
  proxy: {
    target: 'api host',
    changeOrigin: true,
  },
  mock: {
    '/url_a': {},
    '/url_b': {},
  },
}

Run this command to use the config file:

mock -c # default config file mock.config.js 
mock -c my.mock.config.js # customize config file 

Record & Replay

node-http-mock can construct mock data from real HTTP streams.It identify APIs according to request url, request method and query strings.

[method] [url] ? [query string]

Use -r option to recording these responses as ordinary JSON files in .mock/:

mock -r [directory path]

Press Crtl-C will terminate recording and create index.js tracing the JSON files.After that you can import the index.js into your config file manually:

module.exports = {
  // ...
  mock: require('./.mock/index.js'),
}

Options

Run this command to see a list of all available options:

mock --help

License

MIT © BinRui.Guan

Readme

Keywords

Package Sidebar

Install

npm i node-http-mock

Weekly Downloads

19

Version

0.5.2

License

MIT

Last publish

Collaborators

  • differui