mapping files using readdirsync with es6 modules

469 Views Asked by At

In my Node project I'm using es6 imports instead of commonjs' require().

I've found this snippet to map through a folder and insert the files as the second argument to app.use():

readdirSync('./routes').map(r => app.use('/', require('./routes/' r)));

Can I translate this to es6 import syntax?

1

There are 1 best solutions below

0
Abhishek Kumar Sharma On

try this:

readdirSync('./routes').map((r) => app.use('/api/v1', require('./routes/'+r)))