无法让样式表与node.js的ejs一起工作

我试图做一个简单的服务器与节点,expression和ejs的模板。 我已经得到了服务器指向页面,加载它,甚至能够用include语句生成其他代码位。 但是由于某种原因样式表不会加载。

app.js

var express = require('express'), app = express(), http = require('http'), server = http.createServer(app), fs = require('fs'); var PORT = 8080; app.set('view engine', 'ejs'); app.get('/', function(req, res){ res.render('board.ejs', { title: "anything I want", taco: "hello world", something: "foo bar", layout: false }); }); app.listen(PORT); console.log("Server working"); 

ejs文件位于目录views / board.ejs中

 <html> <head> <title><%= title %></title> <link rel='stylesheet' href='../styles/style.css' /> </head> <body > <h1> <%= taco %> </h1> <p> <%= something %> </p> </body> </html> 

而style.css位于相对于app.js的styles / style.css目录中

 p { color:red; } 

我已经尝试了我可以设想的链接的href,包括相对于我的本地主机相对于app.js相对于board.ejs的位置,甚至只是style.css,但似乎没有任何工作。 任何build议,非常感谢。

声明一个静态目录:

 app.use(express.static(__dirname + '/public')); <link rel='stylesheet' href='/style.css' /> 

在app.js中:

  you must first declare static directory app.use("/styles",express.static(__dirname + "/styles")); 

在ejs文件中:

 <link rel='stylesheet' href='/styles/style.css' />