GrafGenerator / gulp-json-server

Gulp plugin-wrapper for json-server
MIT License
16 stars 8 forks source link

mockapi.kill is not a function #15

Closed bondarewicz closed 8 years ago

bondarewicz commented 8 years ago

having following gulp file

var gulp = require('gulp');
var api = require('gulp-json-srv');

gulp.task('mock-api-start', function () {

  api.start({
        data: 'db.json',
        port: 3004
    });

});

gulp.task('mock-api-stop', function() {
  api.kill();
});

and calling mock-api-stop after mock-api-start task I get

gulp mock-api-stop
[12:18:01] Using gulpfile gulpfile.js
[12:18:01] Starting 'mock-api-stop'...
[12:18:01] 'mock-api-stop' errored after 120 μs
[12:18:01] TypeError: api.kill is not a function
    at Gulp.<anonymous> (/Users/.../mock-api.js:17:7)
    at module.exports (/Users/.../node_modules/orchestrator/lib/runTask.js:34:7)
    at Gulp.Orchestrator._runTask (/Users/.../node_modules/orchestrator/index.js:273:3)
    at Gulp.Orchestrator._runStep (/Users/.../node_modules/orchestrator/index.js:214:10)
    at Gulp.Orchestrator.start (/Users/.../node_modules/orchestrator/index.js:134:8)
    at /usr/local/lib/node_modules/gulp/bin/gulp.js:129:20
    at doNTCallback0 (node.js:430:9)
    at process._tickCallback (node.js:359:13)
    at Function.Module.runMain (module.js:459:11)
    at startup (node.js:138:18)
    at node.js:974:3

package.json contains "gulp-json-srv": "^0.2.0",

UPDATE I guess it needs to be below ?

var mockApi = jsonServer.start({
        data: 'db.json',
        port: 3004,
    });

and then mockApi.kill();

GrafGenerator commented 8 years ago

@bondarewicz Yes, you're right with update - you need to obtain running server instance after you started it using jsonServer.start(...) and then use that instance's method kill() to kill it. Honestly, it's confusing naming, and I'm preparing new version that will fix it.