express-app-boot
A simple Express App utility to bootstrap the server.
Install
sudo npm install --save express-app-boot
Usage
var app = ;var ROOT_DIR = __dirname;//boot configuration will be loaded at ROOT_DIRvar boot = ROOT_DIR; var PORT = processenvPORT || 3000;//second parameter stands for dir path of boot scripts;/*...*///maybe some custom logic before startapp;//At the end, start the serverifrequiremain === module appstart{ //start logic app; }; else //In case you want to use app in your tests. moduleexports = 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