Socket
Book a DemoInstallSign in
Socket

node-http-mock

Package Overview
Dependencies
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-http-mock

A HTTP mock server for node.js

latest
npmnpm
Version
0.5.2
Version published
Weekly downloads
1
-75%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

rollup

FAQs

Package last updated on 02 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts