req-dir

require all files from a path

Usage no npm install needed!

<script type="module">
  import reqDir from 'https://cdn.skypack.dev/req-dir';
</script>

README

This module require all files from a directory (only .json, .js, and .coffee), inside a path you want, and return a object with this modules.

Usage

First install

npm i --save req-dir

And in your files, use:

var reqDir = require('req-dir');
var path = '.'; // path to dir, in this case, same directory
var controllers = reqDir(path);

Other examples:

var controllers = reqDir('./controllers');
var controllers = reqDir('../controllers');

Important

The path is relative to the file that calls the reqDir.

Tests

I use mocha for tests, first install mocha as global

npm i -g mocha

Then run tests with:

npm test

Enjoy!