Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including exporter with all npm packages installed. Try it out:

var exporter = require("exporter")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

exporter v0.0.2

Help export your modules by file or directory and store in global

Node Exporter

Useful modules exporter for global use.

We always need load modules with following codes:

var email = require('../../helpers/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 $ = require('exporter');

$('email', __dirname + '/email.js');

Use it

var $ = require('exporter');

// Use it


npm install exporter



In bootstrap file, such as app.js in Express.

Export variables

var $ = require('exporter');

// Load with variables
$.debug = true;
$.env = process.ENV['NODE_ENV'];

Export modules from file or directory

Project structure such as:

- app.js
- helpers/
  - uploader.js
  - image.js
  - email.js
  - tools/
    - guid.js


// Set module directly
$.uploader = require('./helpers/uploader');

// Or use exporter
$.email = $(__dirname + '/helpers/email.js');

// And it's same as follow

// Or use function export only
$('email', __dirname + '/helpers/email.js');

// Export modules in directory
$.helpers = $(__dirname + './helpers');

// Export modules recursive in directory
$('allHelpers', __dirname + '/helpers', true);

Use exporter

In your process file or Express controller

var $ = require('exporter');

if ($.debug && $.env == 'product') {
    // Some logic

var guid = $;
var sendEmail = $;
var uploader = $.uploader;


In Express application. You can use to export all routes.

var $ = require('exporter');

$.routes = $(__dirname + '/routes', true);

If you have the structure such as:

- routes/
  - register.js
  - api/
    - users.js

And you can use it simply

var $ = require('exporter');

app.get('/register', $.routes.register);
app.get('/api/users', $.routes.api.users);
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free