5

So instead of using

import A from './directory1/A'
import B from './directory1/B'
import C from './directory2/C'
import D from './directory3/D'

How can I programmatically write a function that reads from all the directories in my current module parent, and loads the modules inside each directory?

odiseo
  • 6,754
  • 2
  • 20
  • 21
  • Does it need to be recursive (look for subfolders) ? I suggest you take a look at this : http://stackoverflow.com/questions/2727167/getting-all-filenames-in-a-directory-with-node-js – Jeff Noel Jan 09 '17 at 19:37
  • 5
    You can't. The main feature of ES6 modules is that they can be statically analyzed. If you need to do this dynamically, use `require` or `System.import`, depending on the setup. – Estus Flask Jan 09 '17 at 19:42
  • 1
    _"that reads from all the directories"_ JavaScript doesn't know about directories. In which environment will the code run? – a better oliver Jan 10 '17 at 09:54

0 Answers0