2.0.3 • Published 4 years ago

import-all-index v2.0.3

Weekly downloads
66
License
MIT
Repository
github
Last release
4 years ago

import-all-index

Uses dynamic import() to recursively loop through a directory tree, import all index.js or index.mjs files and return an array of references to the imported modules

Requires esm package or Node 12.

Usage:

import path from 'path'
import importAllIndex from 'import-all-index'

export default async server => {
  let absolutePath = import.meta.url.replace('file://', '')
  let apiRoutes = await importAllIndex(path.resolve(absolutePath, '../folder_to_import'))

  apiRoutes.forEach(importedModule => {
    if (importedModule.default && typeof importedModule.default === 'function') {
      importedModule.default(server) // runs all imported defaults that are functions injecting the server object provided to the parent function
    }
  })
}
2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.0

6 years ago

0.1.4

6 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago