nin-express-mock
v1.0.1
Published
Mock server powered by Express.js
Downloads
7
Readme
express-mock
Mock server powered by Express.js Extend package express-mock-server(https://www.npmjs.com/package/express-mock-server) to support XML responses and introduce Morgan for log file generation
Installation
npm i -D nin-express-mock
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) {
...
Response xml
module.exports = [
{
request: {
'method': 'GET',
'path': '/some-url'
},
response: {
'statusCode': 200,
'contentType': 'application/xml',
'body': {
'Users': {
'User': [
{
'id': 1,
'name': 'User1',
},
{
'id': 2,
'name': 'User2',
}
]
}
},
}
}
];
## Basic use
```javascript
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',
logConfig: {
isLogEnabled: true,
logFormat: ':response-time ms :method :status :url :req-headers :req-body :req-query',
logFile: 'access.log',
logRotate: '1d',
logDir: path.join(__dirname, 'logs')
}
};
/**
* Return strated Server instance
function can be called are
start
close
* @param {Array} sources
* @param {?Object} opt_serverConfig
* @return {Server}
*/
serverStart(sources [, opt_serverConfig])