我正在尝试将一个简单的html / css / js应用程序部署到Heroku,并且已经使用Node.js设置了我的后端,如下所示:
(server.js)
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
app.use(express.static('dice-game'));
//routes
app.get("/",function(req,res) {
res.render("index");
})
app.listen(port,function() {
console.log("app running");
})
(Procfile)
web: npm server.js
(package.json)
{
"name": "dice-game","version": "1.0.0","description": "js application","scripts": {
"start": "node server.js","test": "echo \"Error: no test specified\" && exit 1"
},"engines": {
"node": "9.8.0"
},"repository": {
"type": "git","url": "git+https://github.com/zay-asad/dice-game.git"
},"author": "zayan asad","license": "ISC","bugs": {
"url": "https://github.com/zay-asad/dice-game/issues"
},"homepage": "https://github.com/zay-asad/dice-game#readme","dependencies": {
"express": "^4.17.1"
}
}
每当我尝试使用“ node server.js” 在本地运行节点时,都会收到以下错误消息:
错误:
No default engine was specified and no extension was provided.
at new View (/Users/oas03/dice-game/node_modules/express/lib/view.js:61:11)
at Function.render (/Users/oas03/dice-game/node_modules/express/lib/application.js:570:12)
at ServerResponse.render (/Users/oas03/dice-game/node_modules/express/lib/response.js:1012:7)
at /Users/oas03/dice-game/server.js:10:9
at Layer.handle [as handle_request] (/Users/oas03/dice-game/node_modules/express/lib/router/layer.js:95:5)
at next (/Users/oas03/dice-game/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/Users/oas03/dice-game/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/Users/oas03/dice-game/node_modules/express/lib/router/layer.js:95:5)
at /Users/oas03/dice-game/node_modules/express/lib/router/index.js:281:22
at Function.process_params (/Users/oas03/dice-game/node_modules/express/lib/router/index.js:335:12)
此外,Heroku说我的应用程序已成功部署,但是每当我从UI中单击“打开应用程序”时,我都会得到这个
有人以前有这个问题吗?任何帮助将不胜感激
更新
所以我现在这样设置
var path = require("path");
var express = require('express');
var app = express();
var port = process.env.PORT || 8080;
app.use(express.static('dice-game'));
//routes
app.get("/",res) {
res.sendFile('index.html',{
root: path.join('dice-game',"dice-game")
});
})
app.listen(port,function() {
console.log("app running");
})
但是我得到错误:ENOENT:没有这样的文件或目录,stat'/Users/oas03/dice-game/dice-game/dice-game/index.html'
有什么想法吗? @Mark