Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asset paths in express

I used the following to declare my asset paths in my node app:

app.use("/styles", express.static(__dirname + '/public/styles'));
app.use("/images", express.static(__dirname + '/public/images'));
app.use("/script", express.static(__dirname + '/public/script'));

...but it seems to be adding the url path (e.g. '/search') in the asset path which then passes it through the logic. All paths are relative for portability - how do I avoid this?

Thanks in advance... :)

James

like image 538
user1775718 Avatar asked Oct 29 '25 01:10

user1775718


1 Answers

Just do this and you'll be done:

app.use(express.static(__dirname + '/public'));
like image 70
Peter Lyons Avatar answered Oct 30 '25 14:10

Peter Lyons