它在 Mac 上运行。
所有文件都在Library/WebServer/Documents/。
当我运行 node index.js 时,代码:
<link rel="stylesheet" href="css/style.css" /> returns: {
Failed to load resource: the server responded with a status of 404 (Not Found)
}
但是,如果我打开 html 文件,它会读取所有内容。
背后的丑陋错误是什么?
最佳答案
您应该在使用它们之前包含这些资源。
你可以这样做:app.use(express.static(__dirname + '/public'));
'public' 是您将拥有静态内容(如图像/JS/CSS)的文件夹。
欲了解更多信息,请访问:http://expressjs.com/en/starter/static-files.html
关于javascript - Node.js 的索引页面不读取 css 或 javascript 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37543819/