Node Exporter
Useful modules exporter for global use.
We always need load modules with following codes:
var email =
If create much more files and directories, I will angry with using the absolute path. So there is a exporter, it is global definition for you.
Load modules:
var $ = ; ;
Use it
var $ = ; // Use it$;
Install
npm install exporter
Usage
Export
In bootstrap file, such as app.js
in Express.
Export variables
var $ = ; // Load with variables$debug = true;$env = processENV'NODE_ENV';
Export modules from file or directory
Project structure such as:
- app.js
- helpers/
- uploader.js
- image.js
- email.js
- tools/
- guid.js
Export
// Set module directly$uploader = ; // Or use exporter$email = ; // And it's same as follow // Or use function export only; // Export modules in directory$helpers = ; // Export modules recursive in directory;
Use exporter
In your process file or Express
controller
var $ = ; if $debug && $env == 'product' // Some logic var guid = $allHelperstools;var sendEmail = $helpersemail;var uploader = $uploader;
More
In Express
application. You can use to export all routes.
var $ = ; $routes = ;
If you have the structure such as:
- routes/
- register.js
- api/
- users.js
And you can use it simply
var $ = ; app;app;