dynamic-ts-modules
A tiny lib that imports Typescript modules (services) dynamically with minimal external dependencies(fs-extra).
At that moment "DynamicLoader" class dynamic import modules.
Examples of usage can see in folder "./examples".
How to use "DynamicLoader" class:
General
loadJson
; .catch
loadModuleByPath
; .catch
Examples of using
1. Example of using DynamicLoader with "Coworkers" lib
In folder "./examples" You can see "coworkersApp.ts" source code.
For testing this example You must have working AMQP server or use some services in the internet
which support this protocol.
Include Your token for AMQP server in "./examples/token.ts" file and run command:
npm run example:coworkers
After this You can publish a massage for "processorFnQueue", "processorFnMakerQueue" or "processorFnFactoryQueue" in AMQP manager.
Result You will see in console when was running "npm run example:coworkers" command
2. Example of using DynamicLoader with "Node.js Express" framework
In folder "./examples" You can see "expressApp.ts" source code.
For testing this example just run command:
npm run example:express
After this You can visit "http://localhost:3000" URL or send GET request to this URL by any HTTP Request manager.
Result You will see in Your browser of HTTP Request manager and console when was running "npm run example:express" command.
3. Example of using DynamicLoader with config file and example of service
Loading service
; // importing "DynamicLoader" class; // .json config file interface and processor module interface .catch
4. Example of using DynamicLoader with config file and examples of function service, function maker service and function factory service
In folder "./examples" You can see file "processorTypesDemo.ts", just run command:
npm run examples:procs
After that You can see result of work function service, function maker service and function factory service in console where command was running.
Specialized loaders
loadConfig
Using for load config.json file which implements "IConfig" interface.
Used in example #3.
; .catch
loadModules
Using for loading modules.
Example of using can see in "expressApp.ts" in dynamic loading "handlerFactory".
loadProcessor
Using for loading service's processor in loadService method which used in example #3.
Testing
You can test "DynamicLoader" class using command:
npm test