Skip to content

hujunhaorobert/express-mock-server

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-mock-server

Mock server powered by Express.js

Installation

npm i -D express-mock-server

Example of source file

module.exports = [
  {
    request: {
      'method': 'GET',
      'path': '/some-url'
    },
    response: {
      'statusCode': 200,
      'body': JSON.stringify({
        'param1': 'some text',
        'param2': 123123,
        'param3': false
      })
    }
  }
];

Response can be a function

response: function(urlParams, qsParams, bodyParams) {
  ...

Basic use

import { serverStart } from 'express-mock-server';

var sources = [
  require('./mock/source1.js'),
  require('./mock/source2.js'),
  ...
];

// this is default configuration
var opt_serverConfig = {
  port: 8080,
  controlApiUrl: '/api/v1'
};

/**
 *  Return strated Server instance
     function can be called are 
        start
        close
 *  @param {Array} sources
 *  @param {?Object} opt_serverConfig
 *  @return {Server}
 */
serverStart(sources [, opt_serverConfig])
  

About

Mock server powered by Express.js

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%