Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将.ejs更改为.html_Javascript_Html_Node.js_Heroku_Ejs - Fatal编程技术网

Javascript 将.ejs更改为.html

Javascript 将.ejs更改为.html,javascript,html,node.js,heroku,ejs,Javascript,Html,Node.js,Heroku,Ejs,如何使下面的server.js代码用于.html文件,而不是节点js中的.ejs。谢谢 var express = require('express'); var app = express(); // set the port of our application // process.env.PORT lets the port be set by Heroku var port = process.env.PORT || 8080; // set the view engine to

如何使下面的server.js代码用于.html文件,而不是节点js中的.ejs。谢谢

var express = require('express');
var app = express();

// set the port of our application
// process.env.PORT lets the port be set by Heroku
var port = process.env.PORT || 8080;

// set the view engine to ejs
app.set('view engine', 'ejs');

// make express look in the public directory for assets (css/js/img)
app.use(express.static(__dirname + '/public'));

// set the home page route
app.get('/', function(req, res) {

// ejs render automatically looks in the views folder
res.render('index');
});

app.listen(port, function() {
console.log('Our app is running on http://localhost:' + port);
});

您应该能够删除这些行:

// set the view engine to ejs
app.set('view engine', 'ejs');

// set the home page route
app.get('/', function(req, res) {
  // ejs render automatically looks in the views folder
  res.render('index');
});
并将.html文件添加到public/

用这段代码测试它

var express = require('express');
var app = express();

// set the port of our application
// process.env.PORT lets the port be set by Heroku
var port = process.env.PORT || 8080;

// make express look in the public directory for assets (css/js/img)
app.use(express.static(__dirname + '/public'));


app.listen(port, function() {
  console.log('Our app is running on http://localhost:' + port);
});
这个目录结构

├── package.json
├── public
│   └── index.html
└── server.js

对我来说很好。

@lessio它说现在无法获取/访问heroku。我建议这是heroku的一些配置问题。代码对我来说似乎工作得很好!在我的答案中添加更多信息