Wondering what’s next for npm?Check out our public roadmap! »

    require-children

    0.0.8 • Public • Published

    Require Children

    Easily and safely require a directory as an object whose keys are its children's filenames (without their extensions), and whose values are its children as modules.

    Example

    To require a directory resources/ with children posts.js, comments.js, and users.js:

    var resources = requireChildren('./resources', module);
     
    /**
     * Now all modules contained in ./resources/ are in the object:
     *
     * resources = {
     *   comments: [object Object],
     *   posts: [object Object],
     *   users: [object Object]
     * } 
     */

    Installation

    npm install require-children

    Usage

    requireChildren(directory, destinationModule);

    requireChildren always returns a children object. The keys of the children object are the names of the modules that were successfully loaded from directory without their extensions or any spaces.

    params

    • directory: The directory to require children of.
    • destinationModule: The module that is requiring the directory children.

    Install

    npm i require-children

    DownloadsWeekly Downloads

    0

    Version

    0.0.8

    License

    ISC

    Last publish

    Collaborators

    • avatar