Say I have this structure:


and in app.js I have:

const express = require('express');
const app = express();

app.use('/docs', (req,res) => {


the problem is since the server is most likely running from the project root directory, the index.html file won't have the right path to pick up the assets.js file.

For example, in index.html if base is set like so:

<base href="/">

that won't work. I could try using:

<base href="node_modules/xxx/">

Another solution would be to bundle everything together so that the index.html file doesn't need to make any requests for static assets, but I am looking for a good solution for how make sure the path resolution works somewhat generically. For example, if the express server is not launched in the project root, but another subdir.


So I think there's two different ways to solve this:

  1. use absolute urls to files on the WWW (for example, use a CDN), instead of relative urls to local files

  2. concatenate everything into one file, so you can serve that file and not have to worry about any relative urls in that html file

With an Angular7 app, I chose option #1. You can do a production build like so: https://stackoverflow.com/questions/53680473/how-to-point-angular-static-assets-to-www-url

and also see: https://blog.chai-jay.com/angular-2-use-cdn-path-angular-cli-generated-index-html/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.