我正在学习使用node.js。从file:///C:/.../myfolder/index.html
运行时,我有我的jQuery和引导文件的目录myfolder/css/
和myfolder/js
在http:// localhost而不是file://上查看站点,使用node.js
该网站看起来不错。
但是当我运行node index.js
并转到localhost:3000
时,找不到这些css和js文件。
这是在我的index.html文件:
<link href="/css/bootstrap.min.css" rel="stylesheet">
<script src="/js/bootstrap.min.js"></script>
<script src="/js/jquery.js"></script>
<script src="/socket.io/socket.io.js"></script>
是否有一定的NodeJS文件夹中我应该存储这些文件?或者我必须在index.js中放入一些代码来导入所有的css和js文件?
最接近的答案!在通过快速文档拖网之后,我发现通过添加行app.use(express.static(__ dirname +'/ public'));我的css和js文件夹在公共文件夹中,它的工作原理。 – flyinglizard 2014-11-09 02:56:26