0
我在使用express和ejs的node.js項目上試圖使用樣式表和javascript文件。在node.js + express + ejs上包含css和js文件
我的結構:
public/
-- css/
-- js/
-- images/
和我chat.ejs文件:
<!DOCTYPE html>
<html lang="en">
<head>
<% include ../partials/head %>
</head>
<body>
.. content ..
<% include ../partials/footer %>
</body>
</html>
,並在我的諧音/ head.ejs有代碼
<link href="public/css/custom.css" rel="stylesheet">
,它應該加載樣式文件,但它不。順便說一句我的主chat.js:
var express = require('express');
var app = express();
// set the view engine to ejs
app.set('view engine', 'ejs');
app.use(express.static(__dirname + '/public'));
// index page
app.get('/', function(req, res) {
res.render('pages/chat');
});
app.listen(3000, function(){
console.log('listening on *:3000');
});
所以如何正確使用它?