https://github.com/quartercastle/autoloader
Autoload modules and json files in Node.js
https://github.com/quartercastle/autoloader
autoloader js json modules nodejs specla
Last synced: over 1 year ago
JSON representation
Autoload modules and json files in Node.js
- Host: GitHub
- URL: https://github.com/quartercastle/autoloader
- Owner: quartercastle
- License: mit
- Created: 2016-04-21T16:07:53.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2017-10-12T21:27:14.000Z (over 8 years ago)
- Last Synced: 2024-04-14T11:08:42.901Z (about 2 years ago)
- Topics: autoloader, js, json, modules, nodejs, specla
- Language: JavaScript
- Homepage:
- Size: 122 KB
- Stars: 5
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Specla Autoloader
[](https://www.npmjs.com/package/specla-autoloader)
[](https://travis-ci.org/specla/autoloader)
[](https://coveralls.io/github/specla/autoloader?branch=release-1.0)
[](https://david-dm.org/specla/autoloader)
[](http://standardjs.com/)
Autoload `modules` and `json` files with ease. This packages constructs an object
that reflects your folder structure and requires the files within the
specified path.
### Install
```sh
npm install --save @specla/autoloader
```
### Usage
```js
const path = require('path')
const Autoloader = require('@specla/autoloader')
const modules = new Autoloader(path.resolve('./modules'))
```
An example of the path `./modules` could look like this.
```
┬ modules
├── some-file.js
├── data.json
├─┬ sub-modules
├── other-file.js
```
This will create the following js object when the path is autoloaded.
```js
const modules = {
'some-file': require('./modules/some-file.js'),
data: require('./modules/data.json'),
'sub-modules': {
'other-file': require('./modules/sub-modules/other-file.js')
}
}
```
### Options
```js
const modules = new Autoloader(__dirname, {
include: ['js', 'json'], // specifies which file types to include
ignore: [
'node_modules', // ignore folders
'some-file.js' // ignore specific file
]
})
```