I have a mean-stack
application. By going to https://localhost:3000/#/home
, it reads views/index.ejs
. Here is the setting in app.js
:
var app = express();
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.all('/*', function(req, res, next) {
res.sendFile('index.ejs', { root: __dirname });
});
Actually, I don't use the feature of ejs
in index.ejs
. So now I want to use just a index.html
rather than index.ejs
.
I put the content of index.ejs
in public/htmls/index.html
and views/index.html
. And here is the current setting in app.js
:
var app = express();
// app.set('views', path.join(__dirname, 'views'));
// app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'public')));
app.all('/*', function(req, res, next) {
res.sendFile('index.html', { root: __dirname });
// res.sendFile('index.html'); // does not work either
});
However, running https://localhost:3000/#/home
returns
Error: No default engine was specified and no extension was provided.
Does anyone know how to fix it?
Edit 1: by following the answer of user818510
, I tried res.sendFile('index.html', { root: path.join(__dirname, 'views') });
in app.js
, it still can NOT find index.html
.
Whereas, in routes/index.js
, the following can find index.html
, but it gives a warning express deprecated res.sendfile: Use res.sendFile instead routes/index.js:460:9
.
var express = require('express');
var router = express.Router();
var path = require('path');
... ...
router.get('*', function(req, res) {
res.sendfile('./views/index.html'); // works, but a deprecation warning
// res.sendFile('index.html', { root: path.join(__dirname, 'views') }); does not work
});
It is really confusing...