title: setting content type for static javascript files in express
body: <p>I am using <code>express</code> to serve up a page with js files using es6 modules.
  About es6 modules - <a href="https://jakearchibald.com/2017/es-modules-in-browsers/" rel="nofollow noreferrer">https://jakearchibald.com/2017/es-modules-in-browsers/</a></p>
  
  <p>my server.js file is - </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const app = express();
  app.use( express.static( __dirname + '/src' ));
  
  app.get('*', (req, res) =&gt; {
     res.sendFile(path.join(__dirname + '/index.html'));
  });
      
  app.listen(8080, () =&gt; console.log('Listening on port 8080!'));</code></pre>
  </div>
  </div>
  </p>
  
  <p>and my index.html is - </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html lang="en"&gt;
    &lt;body&gt;
      &lt;script type="module" src="./src/test.js"&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>In the file <code>test.js</code> i am using es6 modules, thus the <code>type="module"</code> in the script tag.</p>
  
  <p>But <code>test.js</code> script is not loading when i serve this html in browser. It is giving the error -</p>
  
  <pre><code>Failed to load module script: The server responded with a non-JavaScript MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
  </code></pre>
  
  <p>I tried adding the mime type for js files in express using this in the <code>server.js</code> file  - </p>
  
  <pre><code>express.static.mime.define({'application/javascript': ['js']});
  </code></pre>
  
  <p>But still the same result. I guess i need to somehow send the mime/content-type from express for js files, but how?
  Please help.</p>