Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 1,000,000+ packages pre-installed, including stubrec with all npm packages installed. Try it out:

var stubrec = require("stubrec")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

stubrec v0.4.1

record stub json file

Stubrec Build Status

Stubrec records json file and proxy request and response.

Usage

$ npm install stubrec -S
var Stubrec = require('stubrec');
var stubrec = new Stubrec({
  // proxy property specifies backend server
  proxy : "http://localhost:3001", 
  // debug print on
  debug : true
});
var http = require("http");

http.createServer(function(req, res){
    //record to ./test/test.json
    stubrec.record("./test/test.json", req, res);
}).listen(3000);

http.createServer(function(req, res){
    res.writeHead(200, {'Content-Type': 'application/json'});
    res.end('{"hello":"world"}');
}).listen(3001);

http.get("http://localhost:3000/", function(res){
    var data = '';
    res.on("data", function(chunk){
      data += chunk;
    });
    res.on("end", function(){
      // {"hello":"world"}
      console.log(data);
      done();
    });
});

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free