eXtended REQuest
It requires files from the base path of your app and let you configure alias to other paths for faster refactoring. No more ../..
!!
Features
- No bootstrap required
- No dependencies
- Multiple alias support
- Local path file resolution
- Proxy support (mocks)
Installation
$ npm install xreq --save
Basic usage:
Use it in your modules:
//Current js file at foo/bar/a.jsvar xreq = ;//Require a file at other/folder/b.js, only searh from the base pathvar b = ;
How it works
It searches the package.json
of your project, and build routes from that point.
Custom paths
Add some custom paths at package.json
"xreq":
Use it in your modules:
//Current js file at foo/bar/a.jsvar xreq = ;//Require a file at "src/server/services". Use "service" alias as in the xreqvar AService = xreq; // That is better than require('../../src/server/services/AService');
Path resolution
Add a second parameter with value true
var xreq = ; // Print the base location, the folder where the xreq file resides.console; // Print the complete path to file a.hbsconsole; // It works the same way for aliasesconsole;
This method is quite useful for resolve template location or other static files in the local application.
Proxies
Adding a proxy to 'xreq'
;The following line use the proxy ;
If the proxy function returns a falsy value the resolution continues normally.
Removing the proxy
;