【发布时间】:2015-03-30 22:14:34
【问题描述】:
这是我当前的文件夹结构
css
app.css
js
app.js
node-modules
index.html
node-server.js
package.json
节点服务器托管index.html,但我不知道如何加载app.js 和app.css 文件。
index.html 加载它们:
<script src="js/app.js"></script>
<link rel="stylesheet" type="text/css" href="css/app.css"/>
这是错误信息:
Failed to load resource: the server responded with a status of 404 (Not Found)
2http://localhost:3000/css/app.css Failed to load resource: the server
responded with a status of 404 (Not Found)
我知道我需要 require 或加载模块或其他东西,只是不知道是什么。
谢谢
【问题讨论】:
-
那么,呃,你的 node.js 服务器代码在哪里?
-
您必须在您的快递应用程序中添加类似
app.use(express.static('css'));的内容,然后使用href="/app.css"在html 中引用它,但最好将js和css文件夹放入public文件夹,然后将其添加到您的快速应用代码:app.use(express.static('public')); -
哇,呃!我忘了那部分@TomaszKasperek。谢谢。
标签: javascript html css node.js express