title: Express - Edit HTML before serving as static server
body: <p>Before I call <code>expressApp.use(express.static(path.join(__dirname, '/../frontend/dist')));</code> I need to modify the html-code. What I basically need to do is inserting meta tags in two middleware functions. I figured out how to do this. But with my solution I call a middleware-functions inside another one.</p>
  
  <h2>app.js</h2>
  
  <pre><code>let frontend = await fs
    .readFileSync(path.join(__dirname, '/../frontend/dist/index.html'))
    .toString('utf8');
  
  expressApp.use((req, res, next) =&gt; {
    //...
    frontend = frontend.replace(
      '&lt;meta device="ABC" /&gt;',
      '&lt;head&gt;&lt;meta device="' + deviceId + '"/&gt;'
    );
    next();
  });
  
  expressApp.use((req, res, next) =&gt; {
    const language = req.get('language') || 'en_GB';
    logger.info('language:' + language);
    this._languageModule.setLanguage(language);
    frontend = this._languageModule.insertSIDs(frontend);
    logger.info(frontend);
    expressApp.use(express.static(path.join(__dirname, '/../frontend/dist'))); // nested middleware function
    next();
  });
  
  /** set up all the express routes **/
  expressApp.get('/', (req, res) =&gt; {
    res.send(frontend);
  });
  </code></pre>
  
  <h2>Edit</h2>
  
  <p>If I don't call <code>expressApp.use(express.static(path.join(__dirname, '/../frontend/dist')));</code> nested - like this:</p>
  
  <pre><code>expressApp.use((req, res, next) =&gt; {
    const language = req.get('language') || 'en_GB';
    logger.info('language:' + language);
    this._languageModule.setLanguage(language);
    frontend = this._languageModule.insertSIDs(frontend);
    logger.info(frontend);
    next();
  });
  
  expressApp.use(express.static(path.join(__dirname, '/../frontend/dist')));
  </code></pre>
  
  <p>the HTML will not be served modified.</p>