我有这个代码在本地工作正常,但在Heroku中运行时出现错误
var express = require('express')
var app = express()
var path = require('path')
app.use(express.static('public'));
var bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({
extended: true
}));
// parse application/json
app.use(bodyParser.json())
const portNum = 8080
var port = process.env.PORT || portNum;
app.get('/', function (req, res) {
res.sendFile('index.html')
})
然而,当在heroku中运行时,我收到错误:
TypeError: path must be absolute or specify root to res.sendFile
有什么想法吗?
答案 0 :(得分:0)
您可以使用以下方式获取绝对路径:
initialize: function(){
var self = this;
collection.fetch({
success: function(data){
self.collection = data;
}
})
},
render: function(){
var self = this;
var source = $("#template").html();
var template = Handlebars.compile(source);
var htmlToRender = template(self.collection.toJSON());
}