Giter Site home page Giter Site logo

node-auto-loader's Introduction

node-auto-loader

A simple auto loader for nodejs

Build Status

Install

$ sudo npm install auto-loader

Usage

suppose you had a directory structure like this

app/
└── controllers
    ├── Application.js
    └── User.js

you could build a tree with auto-loader like this

var app = require('auto-loader').load(__dirname +'/app')

if you were to console.log the contents of that object you would see this

{ _path: '/Users/jwerle/repos/node-auto-loader/test/app',
  controllers:
   { _path: '/Users/jwerle/repos/node-auto-loader/test/app/controllers',
     Application: [Getter/Setter],
     User: [Getter/Setter] } }

all modules are wrapped in a getter and make a call to require to fetch their definitions and are cached after the first require

app.controllers.Application; // [Function: Application]

api

.load(dir)

  • dir directory to load recursively

example

var loader = require('auto-loader')
var modules = loader.load(__dirname);
console.log(modules);
/**
 { _path: '/Users/jwerle/repos/node-auto-loader/test/module',
  module1: [Getter/Setter],
  module2: [Getter/Setter],
  module3: [Getter/Setter] }
**/

Loader(dir)

creates a new Loader instance

  • dir - root director for loader

example

var loader = new Loader(__dirname)
// load the currenty directory
loader.load();

license

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.