0.0.4 • Published 8 years ago
express-app-boot v0.0.4
express-app-boot
A simple Express App utility to bootstrap the server.
Install
sudo npm install --save express-app-boot
Usage
var app = require('express')();
var ROOT_DIR = __dirname;
//boot configuration will be loaded at ROOT_DIR
var boot = require('express-app-boot')(ROOT_DIR);
var PORT = process.env.PORT || 3000;
//second parameter stands for dir path of boot scripts
boot(app, 'boot');
/*...*/
//maybe some custom logic before start
app.beforeStart(function(app){
/*...*/
});
//At the end, start the server
if(require.main === module){
app.start(function(app){
//start logic
app.listen(PORT);
});
} else {
//In case you want to use app in your tests.
module.exports = app;
}
Configuration
root_dir
- dir path of configuration files, passed in when init boot function
configuration files
- All files are yaml files(you can learn the syntax here)
config.yml
- Put global application options in this file, will be loaded and attacthed to app with the key 'appConfig'.
boot.yml
- Boot configuration file, contains boot task items. These items are grouped into before and after phases respectively.
Task in before phase executes before custom execution logic(app.beforeStart), and after phase task executes when app.start is invoked.
for example,
---
before:
- path: init
name: initializing app
params:
msg: start default booting
- path: session
name: configuring session
params:
key: default-session
collection: session
- path: auth
name: configuring authentication
- path: parse
name: configuring body parse
- path: view
name: setting view engine
params:
path: views
ext: html
after:
- path: @express-routes-loader
name: initializing application routes
params: ../routes
- path: error
name: setting error handlers
boot item should include path
property, which identifies the boot script location. Path starts with @
stands for a npm module name, otherwise is relative to the boot_dir
.
Task within a phase will executes in the order in which it is registered.
Changelog
Latest:
0.0.1
- Initial Commit