generic-import
v3.0.3
Published
Import all modules in a folder with a generic approach.
Downloads
5
Maintainers
Readme
import genericImport from "generic-import";
...express backend initial code
interface MyRouterInterface {
basepath: string,
router: Router // imported from express
}
const routesPath = path.join(process.cwd(), "routes");
const routers = genericImport<MyRouterInterface>(routesPath);
// [
// { filename: "router1", value: Object },
// { filename: "router2", value: Object },
// ]
for(const r of routers){ // for of loop supported in only ES syntax
app.use(r.value.basepath, r.value.router);
}
app.listen(8080);
- camelize boolean Camelizes returned file names of modules
- fileExtensions array Dot prefixed file extensions to include in search
- recursive boolean Enables search in nested folders