Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages

, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); GitHub - vivek43nit/node-app-boot: A app manager for node js to easily start coding and manage your different segment of code very easily · GitHub
Skip to content

Latest commit

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

node-app-boot

Git-Wiki-Page

node-app-boot is a try to build something like spring in nodejs. But it is in very starting phase. It has some primary features this time, which can be further used to develop other features easily.

Where to use :

This module can be used for developing services or web-applications in nodejs

New In v2.0.*

  • Now it has support for defining your own BootAppListener. For understanding its usages better check the code of module node-app-boot-listener-express and test folder of the module for how to use a module implementing BootAppListener.

  • Some bug fixes :

    1. fixed missing error handling if home directory value is missing or invalid
    2. fixed issue of Invalid reference of 'this' inside all stated functions of Child of AppListeners classes.
    3. fixed issue in resolving relative path if passed in home

Current features :

  • AppManager : the main app manager that will handle all app states and will notify all of its listeners.
  • Scanner : This class can be used to scan all files inside a folder that follow a specific conditions.
  • ChainHandler : This class can help you calling your specific functions inside a array of objects sequentially. It will monitor for chain-break-errors and log if any chain break found.
  • BootAppListener : This class will let you develop your own module that can create a skeleton for a service and define your own classes as abstract classes for handling states or getting config at runtime from users for your service. Note :
    1. You can define your own state listeners classes but you have to inherit your class from AppListener class. All the states functions should be called by you except state functions mentioned in AppListener class. State functions mentioned in AppListener classe will be called by AppManager it self for all implementing objects of Child classe.
    2. You can define your class to get Config from user for your service but you have to inherit from ConfigBean class of node-app-boot module. I have created a module by using BootAppListener that provide users, a functionality to define their route in a seperate File and do not worry to link all the routes together. Users just need to define the routes any where he want. Check the module node-app-boot-listener-express in dependent projects and check its code on github for usderstanding how to use BootAppListener class. It also contains test folder that will help you to understand how user will call your module.

Steps to include this manager in your project

Just create your main file in your project folder. Lets we are creating main.js

Code for main.js

var AppManager = require('node-app-boot');
(function () {
if (require.main === module) {
new AppManager({
/* just pass your project root folder path in home
* or define APP_HOME in environment variable( from v2.0 onward )
* You can use environment variable option, if your app start/main file is not in the root directory of your app.
*/
home : __dirname
}).init();
}
}());

Now AppManager will handle all states of a application and call all your AppListeners classes different state functions in sequence based on the priority

Your Classes can listen following states available in AppListener class :

  1. preStart(next) : you can do all your stuffs that need to be loaded before starting your services or http-servers instances. like setting configs in express instances etc. You must call next() after doing your stuffs to continue chaining.
  2. onStart(next) : start your services here. You must call next() after doing your stuffs to continue chaining.
  3. postStart(next) : you can use this section to validating all started services or some post action required after services up. Like sending emails to developers etc. You must call next() after doing your stuffs to continue chaining.
  4. onClose(type, exitCode) : this should be used as closing all your resources gracefully. Does not have next().
  5. onError(err) : this function will be called if some error occurs in your app, and that is not handled inside your code. Does not have next()

Now Lets create two classes where we want to do some state based stuffs:

  1. for loading initial configs from db : ConfigLoaderAppListener.js Just for example create this file inside config folder.
  2. for starting your application : MainAppListener.js

Note : You have to keep your file name ends with 'AppListener', that want to listen different states of app. This is a designing decision just to make sure only your app-listeners will be required so that not all your files get initiallized initially. you can change this behaviour with passing some configuration in AppManager, we will discuss it later.

Code for ConfigLoaderAppListener.js

//getting AppListener class reference
var AppListener = require('node-app-boot').AppListener;
var util = require('util'); //requiring to use inherits function
util.inherits(ConfigLoaderAppListener, AppListener); //you have to inherit your classes from AppListener class
functionConfigLoaderAppListener(){
/** this priority will be used to decide the position of this class in chain calling
* Keep this value maximum for keeping it on most top.
* If you will not declare it then its default value will be 0 * and position of the file will be decided from position of the file in directory traversing.
*/
this.priority = 9999; }
ConfigLoaderAppListener.prototype.preStart = function(next){
console.log("Load configs from db here");
//call next to continue the chain
//If you will not call next or if there is some exception occurs prior to calling this functionthen AppManager will inform you this on console.log
//Just for experiment try once with commenting next() and once with throwing error previous to calling next()
//throw new Error("Checking for what will happen");next();
};
//Note : You do not require to define other methods in all classes
//just define what you require
//Now create this class as singleton
var singleton = new ConfigLoaderAppListener();
module.exports = singleton;

Code for MainAppListener.js

var AppListener = require('node-app-boot').AppListener;
var util = require('util');
//you have to inherit your classes from AppListener class
util.inherits(MainAppListener, AppListener);functionMainAppListener(){
this.priority = 100;
}
//overriding default onStart
MainAppListener.prototype.onStart = function(next){
console.log("Start your services here, or bind the listening port here");next();
};
//overriding default onClose
MainAppListener.prototype.onClose = function(type, exitCode) {
console.log("Stop your services gracefully here");
//this functiondoes not have next function, because you can't stop your app from shutdown from here};var singleton = new MainAppListener();module.exports = singleton;

Running your app

Without DEBUG logging

$ node main.js

With DEBUG logging

$ DEBUG=appmanager:* node main.js

License

MIT

About

A app manager for node js to easily start coding and manage your different segment of code very easily

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages