javascript - what's the best way to find the file in nested folders? -


i found legacy code factory load 1 file sub-tree directory.

var name = 'file.js' try {   return require('folder/foo/' + name) } catch (e) {   try {     return require('folder/foo/bar/' + name)   } catch (ee) {     return null   } } 

how can avoid nested try/catch blocks each folder level? tried this.

const name = 'file.js' const pathlist = ['folder/foo/', 'folder/foo/bar/'] return pathlist.map(path => {         const file = `${path}${name}`         try {             return require(file).default         } catch (exception) {             return null         }     }) 

but changes behaviour. if file not found on first level returns null instead of taking next level. doesn't if change order @ pathlist declaration.

is there better way in react app environment? cannot use fs node.js.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -