简体   繁体   中英

How to serve static files in another folder with express

I have these following files in my folder. I want to show the public folder from index.js using express. At first, I used app.use(express.static('public')) and it works on my localhost but when I deployed it it doesn't work. Can anyone show me how to do this?

(in case the pic doesn't work:

public folder(index.html,style folder,js folder)

.gitignore

.env

index.js)

files

Maybe this is an issue with relative pathing, try replacing your current code with this:

  • app.use("/", express.static(__dirname + "/public"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM