I know I can require a file in ES6 like this:
require('./config/auth');
When I try to do this
require('./config/');
I get: Module not found: Error: Cannot resolve directory './config'
. Why does this happen? How can I require a directory?
I know I can require a file in ES6 like this:
require('./config/auth');
When I try to do this
require('./config/');
I get: Module not found: Error: Cannot resolve directory './config'
. Why does this happen? How can I require a directory?
First of all, your requires are in NodeJS/io.js syntax, module in ES6 syntax looks like this:
import "./config/auth";
Or if you want to load something from it:
import authenticate from "./config/auth";
You can't load whole directories at once, but in Node/io.js you can create a module and then load that.
Note that as a workaround you can load a single file that in turn loads multiple files and returns their results. There is also work in progress on an asynchronous loader but that changes so often it's hard to keep track so I wouldn't rely on it just yet.
I personally use a package called require-dir. This should work for you:
import requireDir from 'require-dir';
requireDir('./config');