Skip to content
Advertisement

Express.Static not working for subdirectory

Express.static is working great for any view in root directory, but it breaks when I add a subdirectory.

JavaScript

Works:

JavaScript

Doesn’t Work:

JavaScript

I’m guessing __dirname is changed to whatever directory the get request is made from, but I just want to use the root (/public) directory for all static requests.

Advertisement

Answer

Use it this way:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement