我是初学者,有节点。我正在尝试提供一个文件。我的项目的层次结构看起来像服务css和javascript文件
应用
modules
node_modules
public
css
index.css
html
index.html
javascript
routes
main.js
内main.js
var express = require('express');
var app = express();
var path = require('path')
var port = 8080;
app.use("/styles", express.static(path.join(__dirname + '../public/css')));
app.use("/scripts", express.static(__dirname + '../public/javascript'));
app.get('/' , function(req , res){
res.sendFile(path.join(__dirname,'../public/html/index.html'))
})
app.listen(port)
我想担任/路由的文件。它工作正常,但CSS和JavaScript的未加载 - 它会抛出错误browswer控制台
http://localhost:8080/css/index.css无法加载资源:在 服务器的404(未找到)
状态回应什么是设置路径到CSS的正确方法?我很难找到合适的解决方案。
谢谢!
你的静态CSS路线被称为“风格”,而不是“css”;尝试'http:// localhost:8080/styles/index.css' – Hamms
@Hamms它没有找到该文件,为什么样式? – Josh