Require all files from app's root path (require-all + app-root-path)
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.gitignore
LICENSE
README.md
index.js
package.json

README.md

Usage

Instead of:

const lib = {
	foo: require('../../lib/foo'),
	bar: require('../../lib/bar'),
	...
}

use:

const req = require('require-all-root')
const lib = req('/lib')

Usage as a require() replacement

require-all-root can import individual files, modules and packages from /node_modules.

const req = require('require-all-root')

// exteral modules
const fs = req('fs')
const express = req('express')

// if /module/index.js exists
const module = req('/module')
// equals to
const module = req('/module/index')
const module = req('/module/index.js')

// if /data.json exists
const data = req('/data')

Usage from global scope

To avoid require('require-all-root') in multiple files, you can setup it ones in а global object

// In start.js
global.req = require('require-all-root')
 
// In /some/path.js 
const lib = req('/lib')

Changelog

1.0.1

  • Module inner errors are thrown
  • Allows to require all for relative path

Thanks