title: How to recursively export all from folders in node js project?
body: <p>In my React JS project I have configured a <code>jsconfig.json</code> such that I can recursively export nested directories and import a specific export from the base directory as follows:</p>
  <p><code>jsconfig.json</code>:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;compilerOptions&quot;: {
      &quot;jsx&quot;: &quot;react&quot;,
      &quot;baseUrl&quot;: &quot;src&quot;
    }
  }
  </code></pre>
  <p>Project folder structure:</p>
  <pre><code>react-app
    src
      common
      index.js
        services
          ServiceA.js
          ServiceB.js
          index.js
        components
          ComponentA.jsx
          index.js
      pages
        pageA
          PageA.jsx
          index.js
      App.jsx
      index.js
      
  </code></pre>
  <p>Now in each <code>index.js</code> I would export all from each file/folder. So for example in <code>common/services/index.js</code>:</p>
  <pre class="lang-js prettyprint-override"><code>export * from 'common/services/ServiceA.js';
  export * from 'common/services/ServiceB.js';
  </code></pre>
  <p>And in <code>common/index.js</code>:</p>
  <pre class="lang-js prettyprint-override"><code>export * from 'common/services';
  export * from 'common/components';
  </code></pre>
  <p>Now if I require <code>ServiceA</code> exported from <code>ServiceA.js</code> in the <code>PageA.jsx</code> file I could import it as follows:</p>
  <pre class="lang-js prettyprint-override"><code>// PageA.jsx
  import {
    ServiceA
  } from 'common';
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>// ServiceA.js
  export class ServiceA {
    doStuff () {
      // do stuff
    }
  }
  </code></pre>
  <p>How can I setup my NodeJS server project to allow for similar exports and imports?</p>
  <p>I'd like to do this for consistency between the FE and BE such that I can easily port over any FE code to my BE project without having to make any significant changes to exports and imports.</p>
  <p><strong>Edit:</strong> I managed to get it working using the answer by Besworks to which I awarded the bounty, however VS Code Intellisense wouldn't navigate to the export definition from the import statement until I added a <code>jsconfig.json</code> in the project root:</p>
  <pre><code>{
      &quot;compilerOptions&quot;: {
          &quot;baseUrl&quot;: &quot;./src&quot;,
          &quot;paths&quot;: {
              &quot;#common&quot; : [&quot;./common/index.js&quot;]
          }
      }
  }
  </code></pre>