title: ReferenceError: module is not defined
body: <p>So i have been trying to run this web app  and at first it showed</p>
  <p>(node:12960) Warning: To load an ES module, set &quot;type&quot;: &quot;module&quot; in the package.json or use the .mjs extension.<br />
  C:\Users\J\react-messenger\stream-chat-boilerplate-api\src\index.js:1<br />
  import dotenv from 'dotenv';
  ^^^^^^</p>
  <p>SyntaxError: Cannot use import statement outside a module</p>
  <p>And then i went to put set the type: module in the package.json but it gave me this error</p>
  <p>ReferenceError: module is not defined</p>
  <pre><code>at file:///C:/Users/J/react-messenger/stream-chat-boilerplate-api/src/index.js:38:1
  </code></pre>
  <p>Here is my code:</p>
  <pre><code>import dotenv from 'dotenv';
  dotenv.config();
  
  import fs from 'fs';
  import path from 'path';
  import express from 'express';
  import bodyParser from 'body-parser';
  import cors from 'cors';
  import helmet from 'helmet';
  import compression from 'compression';
  
  const api = express();
  
  api.use(cors());
  api.use(compression());
  api.use(helmet());
  api.use(bodyParser.urlencoded({ extended: true }));
  api.use(bodyParser.json());
  
  api.listen(process.env.PORT, error =&gt; {
      if (error) {
          console.warn(error);
          process.exit(1);
      }
  
      // eslint-disable-next-line array-callback-return
      fs.readdirSync(path.join(__dirname, 'routes')).map(file =&gt; {
          require('./routes/' + file)(api);
      });
  
      console.info(
          `Running on port ${process.env.PORT} in ${
              process.env.NODE_ENV
          } mode. `
      );
  });
  
  module.exports = api;
  
  </code></pre>
  <p>I dont know what am doing wrong</p>