在本地主机服务器上找不到png文件
错误代码http:// localhost:3000 / public / resource / calendar.png加载资源失败:服务器响应状态为404(未find)
我想要Web服务。 我不知道为什么这个错误。
它在本地文件中运行良好,但是从nodejs开始这个错误
错误
这是我的来源
app.js
var express = require('express'), app = express(), server = require('http').createServer(app), io = require('socket.io').listen(server); server.listen(3000); app.get('/', function(req, res){ res.sendFile(__dirname + '/index.html'); });
index.html(来源太长)
这是错误代码
text-align: center; background: url('./public/resource/calendar.png'); background-size: contain;
而png文件path是D:\ Hackathon \ public \ resource
和app.js,索引path是D:\ Hackathon
帮助我PLZ
您需要安装中间件来提供静态文件。
请参阅https://expressjs.com/en/starter/static-files.html
app.use(express.static('<root_folder_for_resources>'));