node-http-mock
v0.5.2
Published
A HTTP mock server for node.js
Readme
node-http-mock
A HTTP mock server for node.js
Usage
Install it:
npm install node-http-mock -gAnd 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 fileRecord & 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 --helpLicense
MIT © BinRui.Guan
