Sometimes, we want to fix Express.js not getting static files.
In this article, we’ll look at how to fix Express.js not getting static files.
How to fix Express.js not getting static files?
To fix Express.js not getting static files, we call express.staric
with the path to the static files.
For instance, we write
app.use("/styles", express.static(__dirname + '/styles'));
to call app.use
with the path to the static files and the middleware returned by expres.static
called with the path to the /styles
folder in the directory.
__dirname
is the path of the Express project folder.
As a result, we should be able to access the files in the styles
folder with the /styles
path.
Conclusion
To fix Express.js not getting static files, we call express.staric
with the path to the static files.