Javascript NODE.JS如何使用NODE.JS显示位于名为css的文件夹内的css文件,其中my server.JS和index.html位于文件夹外
所以,我是新来的Javascript NODE.JS如何使用NODE.JS显示位于名为css的文件夹内的css文件,其中my server.JS和index.html位于文件夹外,javascript,jquery,html,css,node.js,Javascript,Jquery,Html,Css,Node.js,所以,我是新来的节点js。我的文件夹看起来像这样 NODE //my main folder here ->CSS //this is a folder ->IMAGES //this is a folder ->node_modules //this is a folder where intalled npms are stored ->index.html ->
节点js
。我的文件夹看起来像这样
NODE //my main folder here
->CSS //this is a folder
->IMAGES //this is a folder
->node_modules //this is a folder where intalled npms are stored
->index.html
->server.js
我希望我的style.css
在css文件夹
中,使用node.js
显示在我的index.html
中
如果您能在index.html中提供帮助,我将不胜感激
<link rel="stylesheet" href="style.css">
最佳做法是将主目录中的文件夹设为公共文件夹。它应该包含comman所需的所有css、js、assets文件夹,然后放在服务器文件上
app.use(express.static('public'))
对于您的情况,您可以使用:
app.use(express.static('CSS'))
之后,您可以像在普通html文件中一样直接链接css或任何其他公共文件。您能否提供一些节点代码,以便我们了解您的系统是如何工作的?我见过的大多数节点应用程序都将服务器文件与浏览器/客户端文件分开。客户端文件将全部存在于名为
public
或client
或类似文件夹下。例如,您将在public
中有HTML文件,在public/CSS
中有CSS文件,在public/JS
中有JS文件,等等。
app.use(express.static('CSS'))