[英]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.我想使用 express 显示 index.js 中的公用文件夹。 At first, I used app.use(express.static('public')) and it works on my localhost but when I deployed it it doesn't work.起初,我使用 app.use(express.static('public')) 并且它在我的本地主机上工作,但是当我部署它时它不起作用。 Can anyone show me how to do this?谁能告诉我如何做到这一点?
(in case the pic doesn't work: (如果图片不起作用:
public folder(index.html,style folder,js folder)公共文件夹(index.html,style文件夹,js文件夹)
.gitignore .gitignore
.env .env
index.js) index.js)
Maybe this is an issue with relative pathing, try replacing your current code with this:也许这是相对路径的问题,请尝试用以下代码替换您当前的代码:
app.use("/", express.static(__dirname + "/public"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.