1.0.2 • Published 7 years ago
@thavith/importmodules v1.0.2
ImportModules
Import Modules dynamically into your NodeJS project. This means you can programatically get the path for your modules. This uses ES6 and mjs files.
####Installation npm i @thavith/importmodules
####How to use
import ImportModules from '@thavith/ImportModules';
class MyClass {
constructor()
// we need events to let us know when the imports have finished
// better than using a callback as we don't lose scope
let emitter = new EventEmitter();
emitter.on("OnImportModules", () => {
// TODO: code to run after importing your modules.
});
// import the needed modules
new ImportModules(this, {
path: process.env.PWD, // path to your project, defaults to process.env.PWD
emitter: emitter,
event: 'OnImportModules',
import: [ // which modules do you want to import
'ModuleToImport_1', // modify the IMPORT_DEFINITIONS file
'ModuleToImport_2', // to your needs
'ModuleToImport_3'
]
});
// rest of your code goes here
...
####Make sure you update IMPORT_DEFINITIONS I will update this later so you can point ImportModules to your own definition