Skip to content

fedor/node-require-all-root

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 

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

About

Require all files from app's root path (require-all + app-root-path)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published