NODE.JS如何使用node.js显示我的CSS文件夹内的名为CSS的文件夹,其中我的server.js和index.html位于文件夹之外
所以,我是新的node 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 folder
中,使用node.js
显示在我的index.html
中。
我将不胜感激您的帮助
在index.html中
<link rel="stylesheet" href="style.css">
在server.js中包含了CSS目录:
app.use(express.static(path.join(__dirname, 'CSS')));
最佳做法是在主目录中创build公用文件夹。 它应该包含所有需要comman的css,js,assets文件夹。然后在你的服务器文件中。
app.use(express.static('public'))
对于你的情况,你可以使用:
app.use(express.static('CSS'))
之后,你可以直接链接CSS或任何其他公共文件,就像你在普通的HTML文件中一样。