Aran Mulholland
Aran Mulholland

Reputation: 23945

Node.js and Require.js include an entire directory

There is a similar question here but it applies to the browser. I was wondering if I could require every file in a directory when using require.js in node.

Is there a short cut or would I have to manually iterate all files in a folder and require them one by one?

Upvotes: 1

Views: 130

Answers (1)

ExxKA
ExxKA

Reputation: 1030

The easiest thing would be to place an index.js file in the directory, which in turn requires all the files in the directory that are related to your project. Then you can require your directory, and require.js will look up all the entries in the index.js file.

Upvotes: 1

Related Questions