diff --git a/README.md b/README.md index 3b5ef9e..8708cee 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,23 @@ Dynamic values of headers can be filled with valid JS statements such as: X-Subject-Token: #header ${require('uuid/v4')()}; ``` +Because of how the javascript files are evaluated, you can also access the following variables inside the .js file: +* `request` +* `context` +* `value` + +Relative `require()` import statements for relative files will not work out-of-the-box, but since `context` contains the path to the directory where your .js file is, you can do the following hack to get them to work. + +```js +/* globals request, context, path */ + +// actually path is already available via the eval'd scope +// var path = require('path'); +var fooFunc = require(path.join(context, 'foo.js')); + +module.exports = fooFunc(request).bar; +``` + ## Custom response status You can specify response status (200, 201, 404. etc.) depending on request parameters. To do this, you need to use `#import './code.js';` in first line of your mock file: