【发布时间】:2017-11-06 12:19:43
【问题描述】:
我正在尝试将一些静态文件加载到 ejs(我能够加载 HTML 文件,但不能加载到 ejs 文件中)。不仅仅是静态文件。 我什至无法加载 CDN 文件!有人可以帮我了解我哪里出错了吗? 这是目录结构:
这是我的 server.js:
const express=require('express');
var app=express();
const MongoClient = require('mongodb').MongoClient
app.set('view engine', 'ejs')
var path = require('path')
app.use('/static',express.static(__dirname + '/public'));
app.get('/',function(req,res){
db.collection('testCollection').find().toArray((err, result) => {
if (err) return console.log(err)
console.log(result)
res.render('index.ejs', {testCollection: result})
})
});
这是我的 index.ejs:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/static/main.css"/>
</head>
<body>
<form>
<div id="container"></div>
<ul class="quotes">
<% for(var i=0; i<testCollection.length; i++) {%>
<li class="quote">
<span><%= testCollection[i].name %></span>
</li>
<% } %>
</ul>
</form>
</body>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="/static/main.js"></script>
</html>
【问题讨论】:
标签: javascript html node.js express ejs