You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 31, 2020. It is now read-only.
[deprecated] Microframework is a simple tool that allows you to execute your modules in proper order, helping you to organize bootstrap code in your application.
Microframework is a simple tool that allows you to execute and configure your modules (called loaders) in a proper order,
helping you to organize bootstrap code in your application.
Usage
First, install microframework:
npm i microframework
Second, create a simple "loader" named expressLoader.
Loader is a place where you can configure all your modules during microframework bootstrap.
All loaders are executed one by one in a sequential order.
import{MicroframeworkSettings}from'microframework';exportfunctionexpressLoader(settings: MicroframeworkSettings){// create express appconstapp=express();// register all routes, Routes are just routes that should be stored outside of this moduleconstroutes: any=Routes;Object.keys(routes).forEach(routePath=>app.get(routePath,routes[routePath]));// run application to listen on given portapp.listen(3000);// your loader also can return a promise and microframework will wait for it in a proper order}
Create app.ts and bootstrap a microframework and your express loader:
import{bootstrapMicroframework}from'microframework';import{expressLoader}from'./expressLoader';bootstrapMicroframework([expressLoader]).then(()=>console.log('Application is up and running.')).catch(error=>console.log('Application is crashed: '+error));
That's all. You can do same for other loaders.
Take a look on sample to understand better how concept of loaders and their bootstrapping in microframework.
Settings
You can specify additional options to microframework.
logo - Logo needs to be used before application launches. To use logo ansi-art node module should be installed.
showBootstrapTime - If set to true then framework shows how much time was spend to bootstrap microframework.
bootstrapTimeout - Number of milliseconds to wait before framework will bootstrap.
Example of using settings:
import{bootstrapMicroframework}from'microframework';import{expressLoader}from'./expressLoader';bootstrapMicroframework({config: {logo: 'MyApp',showBootstrapTime: true,bootstrapTimeout: 10,},loaders: [expressLoader,// ...],}).then(()=>console.log('Application is up and running.')).catch(error=>console.log('Application is crashed: '+error));
Sharing data across loaders
Sometimes few loaders need to communicate between each other and use shared data.
For such purpose you can store the data in settings object passed to each loader
and use stored data across all other loaders. For example:
import{MicroframeworkSettings}from'microframework';exportfunctionexpressLoader(settings: MicroframeworkSettings){// create express appconstapp=express();// register all routes, Routes are just routes that should be stored outside of this loaderconstroutes: any=Routes;Object.keys(routes).forEach(routePath=>app.get(routePath,routes[routePath]));// run application to listen on given portapp.listen(3000);settings.setData('express_app',app);}
In the case if you want to shutdown running application you need to do following:
import{bootstrapMicroframework}from'microframework';import{expressLoader}from'./expressLoader';bootstrapMicroframework({config: {logo: 'MyApp',showBootstrapTime: true,bootstrapTimeout: 10,},loaders: [expressLoader,// ...],}).then(framework=>{// do something before shutdown// and shutdown everythingreturnframework.shutdown();}).then(()=>{// now everything is turned off}).catch(error=>console.log('Application is crashed: '+error));
All loaders which use resources should release them, for example:
[deprecated] Microframework is a simple tool that allows you to execute your modules in proper order, helping you to organize bootstrap code in your application.