Socket
Socket
Sign inDemoInstall

express-load

Package Overview
Dependencies
0
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    express-load

Autoload modules into an Express application instance


Version published
Maintainers
1
Install size
7.54 kB
Created

Readme

Source

Express Load

The express-load module provides the ability to load scripts into an Express instance from a specified directory. Make large express MVC applications easier to develop by allowing a logical file separation without having to include a bunch of files, see the examples folder for information.

Despite being a very simple module, it is extremely useful. It can be used to autoload models, routes, schemas, configs, controllers, object maps... etc...

express-load gives you access to the autoloaded files in the Express application instance to keep out of the global namespace. This also allows access to the scripts via the request object.

A script at ./controllers/user.js becomes available as app.controllers.user or req.app.controllers.user in a request.

Installation

$ npm install express-load

Usage

Multiple Directories

require('express-load')([
	'./models',
	'./controllers',
	'./routes'
], app);

Single Directory

require('express-load')('./routes', app);

The first parameter can be an array of directories or a string. The second parameter must be the Express application instance.

Example

app.js

var express = require('express')
  , load = require('express-load');

var app = express();

load(['./controllers', './routes'], app);

app.listen(3000)

If there were the following files in the controllers folder:

user.js post.js comment.js

They would then be available as: app.controllers.user app.controllers.post app.controllers.comment

Or from within a request as: req.app.controllers.user req.app.controllers.post req.app.controllers.comment

The directories are read synchronously, this is only done once when the app starts allowing the directories listed to have the scripts loaded in the order specified, for example you will want to load the controllers before the routes.

More examples will be available in the examples folder.

License

(The MIT License)

Copyright (c) 2012 Jarrad Seers <jarrad@jarradseers.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 07 Aug 2012

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc