# gulp-json-srv

> Wrapper for json-server for easy launching with Gulp

Latest version **1.2.0** (published 2018-01-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install gulp-json-srv
pnpm add gulp-json-srv
yarn add gulp-json-srv
bun add gulp-json-srv
```

## 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.2.0 |
| Published | 2018-01-24 |
| First published | 2015-06-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 9 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Nikita Ivanov |
| Maintainers | grafgenerator |
| Keywords | gulpplugin, json-server, json, fake, prototyping, test, testing, mock, mocking, REST, API, server |

## Links

- npm: https://www.npmjs.com/package/gulp-json-srv
- Repository: https://github.com/GrafGenerator/gulp-json-server
- Homepage: https://github.com/GrafGenerator/gulp-json-server#readme
- Issues: https://github.com/GrafGenerator/gulp-json-server/issues
- npm.io page: https://npm.io/package/gulp-json-srv

## Dependencies (9)

- [fs](https://npm.io/package/fs.md) 0.0.2
- [chalk](https://npm.io/package/chalk.md) ^2.3.0
- [lodash](https://npm.io/package/lodash.md) ^4.15.0
- [loglevel](https://npm.io/package/loglevel.md) ^1.4.1
- [through2](https://npm.io/package/through2.md) ^2.0.1
- [body-parser](https://npm.io/package/body-parser.md) ^1.15.2
- [json-server](https://npm.io/package/json-server.md) ^0.12.1
- [plugin-error](https://npm.io/package/plugin-error.md) ^1.0.0
- [server-destroy](https://npm.io/package/server-destroy.md) ^1.0.1

## 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.2.0 (latest) — 2018-01-24
- 1.1.0 — 2017-07-07
- 1.0.1 — 2016-09-19
- 1.0.0 — 2016-09-19
- 0.2.0 — 2016-03-14
- 0.1.1 — 2016-01-14
- 0.1.0 — 2016-01-11
- 0.0.7 — 2015-09-07
- 0.0.6 — 2015-09-05
- 0.0.5 — 2015-08-23
- 0.0.4 — 2015-06-23
- 0.0.3 — 2015-06-21

## README

# gulp-json-server [![Build Status](https://travis-ci.org/GrafGenerator/gulp-json-server.svg?branch=master)](https://travis-ci.org/GrafGenerator/gulp-json-server) [![npm version](https://badge.fury.io/js/gulp-json-srv.svg)](https://badge.fury.io/js/gulp-json-srv)

Wrapper for [json-server](https://github.com/typicode/json-server).

**Important!** API versions >1.0.0 are incompatible with ones <1.0.0, see this page for new API, and [examples of usage](SAMPLES.md).

## Install

```
$ npm install --save-dev gulp-json-srv
```


## Usage
```js
var gulp = require("gulp");
var jsonServer = require("gulp-json-srv");

var server = jsonServer.create();

gulp.task("start", function(){
    return gulp.src("data.json")
        .pipe(server.pipe());
});
```

See [samples](SAMPLES.md) for more information about usage of plugin.


## API

### Options

| Options | Default value | Description |
|:---|:---|:---|
|`baseUrl`|`null`|The base URL for server API.|
|`bodyParserJson`|`null`|Allows override of default `bodyParser.json()` method so it is possible to pass in custom options. e.g. `bodyParser.json({limit: '10mb', expanded: false})`.
|`cumulative`|`false`|Controls when to merge files from different `pipe()` calls (i.e. two pipelines execution.)|
|`cumulativeSession`|`true`|Controls when to merge files in one `pipe()` call (i.e. one pipeline execution.). If not, then only last file passed to plugin will form the DB state.|
|`customRoutes`|`null`|A key-value pairs of custom routes that should be applied to server. Each value should be the object with `method` and `handler` properties, describing HTTP method and handler of custom route respectively.|
|`id`|`"id"`|Identity property name of objects. Changing this allows to imitate MongoDB's `_id` f.e.|
|`port`|`3000`|Port number on which json-server will listen.|
|`rewriteRules`|`null`|A key-value pairs of rewrite rules that should be applied to server.|
|`static`|`null`|If specified and not null, sets the static files folder and lets json-server serve static files from that folder.|
|`verbosity`|`{`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`level:"error",`<br/>&nbsp;&nbsp;&nbsp;&nbsp;`urlTracing:true`<br/>`}`|Should be either `string` or `object`. In case value is object, specifies log `level` (see [loglevel](https://www.npmjs.com/package/loglevel) for details), and `urlTracing` flag, which allows to control messages about accessed routes. In case value is string, specifies only log level, and urlTracing is considered to be `true`.|

**Important:** Note that `cumulative` and `cumulativeSession` options could be specified in `options` object, passed to `pipe()` method and they will override one set at server level.

### Methods
| Method | Description |
|---|---|
|`kill(callback)`|Immediately stops the server and closes all opened connections. If `callback` is provided, it will be called once server stopped.|
|`pipe(options)`|Provides stream trasformation for gulp pipeline. Passing `'options'` to this method allows to override options, set at server level (currently `cumulative` and `cumulativeSession` are overridable). |

## Links

* [SAMPLES.md](SAMPLES.md) - more examples of usage
* [CHANGELOG.md](CHANGELOG.md)
* [CONTRIBUTING.md](CONTRIBUTING.md) - info for contributors

## License

MIT © 2016 Nikita Ivanov

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