2.0.0 • Published 4 years ago

mocklocal v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

mocklocal.js

npm version Build Status Coverage Status Dependencies Known Vulnerabilities

mocking an API server with random delays in the response

Installation

npm i -g mocklocal

Basic Usage

To start your mock server:

mocklocal

In separate terminal, you can try this example request

curl localhost:3000/example/mock/ -d '{"test":"1"}' -H "Content-Type: application/json"

Configurations

All these options can be configured through environment variables

PropertyDescriptionDefault value
PORTPort to serve the mock server3000
MIN_DELAYMinimum delay for the mock server in seconds you can also use floating point, with 3 fixed precision0
MAX_DELAYMaximum delay for the mock server in seconds you can also use floating point, with 3 fixed precision3
RESPONSEDefault response body for all requests use req to reply back with the request dont forget to escape your string if you're responding with JSONreq

Example usage with config:

PORT=5000 MIN_DELAY=0 MAX_DELAY=.5 RESPONSE={\"status\":\"ok\"} mocklocal

Usage with stdin

Examples of usage with stdin piped to mocklocal

echo '{"source":"stdin"}' | mocklocal
cat ./response_example.json | mocklocal

Note: using stdin as response will override value set in RESPONSE env variable

Tests

Used nyc, mocha, chai for tests; and coveralls for test coverage

npm test

Todos

  1. Enable floating point in delay (so we can have .1 seconds)
  2. response.json file as response
2.0.0

4 years ago

1.1.0

4 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago