0.1.0 • Published 6 years ago

node-dir-load v0.1.0

Weekly downloads
7
License
MIT
Repository
github
Last release
6 years ago

node-dir-load

npm
A tool to load all files in a directory.

Requirements

Node version is above 4.00, which supports ES6.

For now, just support .js and .json files. Others extension files WILL BE IGNORED!!!

Features

  • load all files in the folder
  • filter the files to load
  • exclude the subdirectory to load
  • lazy require to avoid some error of circular dependency
  • relative directory to load

Get Started

Install with npm:

npm install node-dir-load

Load files from a specific directory into an object.

const load = require('node-dir-load');

const models = load({
  dirname: '../model'
});
console.log(models);
/*
=> 
{ 
  blog: { blog: { getBlogList: [Function] } },
  comment: { getCommentList: [Function] },
}
*/

options

  • dirname
  • recursive
  • excludeDirs
  • filter

dirname

The src directory to load files.Both absolute or relative path are supported! Default is current directory.

recursive

For true, to load subdirectories. Default is true.

excludeDirs

A regular expression to exclude directories to load. It only works when recursive is true. Default exclude hidden files, which begins with '.' .

const models = load({
  dirname: '../model',
  excludeDirs: /^\.(git|svn)$/,
});

filter

A regular expression to filter files to load.Default is .js and .json files.

// just load files begin with user.
const models = load({
  dirname: '../model',
  filter: /^user.+\.js$/,
});

Inspire

Inspire much from node-require-all.

0.1.0

6 years ago

0.0.2

7 years ago

0.0.1

7 years ago