Content in localhost:
TypeError: this.engine is not a function
at View.render (/home/vitalkanev/node_modules/express/lib/view.js:127:8)
at tryRender (/home/vitalkanev/node_modules/express/lib/application.js:640:10)
at Function.render (/home/vitalkanev/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/home/vitalkanev/node_modules/express/lib/response.js:971:7)
at /home/vitalkanev/siteData/expressors/data.js:5:13
at Layer.handle [as handle_request] (/home/vitalkanev/node_modules/express/lib/router/layer.js:95:5)
at next (/home/vitalkanev/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/home/vitalkanev/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/home/vitalkanev/node_modules/express/lib/router/layer.js:95:5)
at /home/vitalkanev/node_modules/express/lib/router/index.js:281:22
Content of the file:
let express = require("express");
let app = express();
app.get("/", function(req, res) {
res.render("./index.html");
});
app.get("/somepage", function(req, res) {
res.render("./somePage.html");
});
app.listen(3000);
Listing of the directory:
vitalkanev@vitalkanev-HP:~/siteData/expressors$ ls
data.js views
Operating System: Lubuntu Zesty
Node version: 8.4.0
NPM version: 5.3.0, as comes with the Node version above
Try this
npm install ejs --save
npm install path --save
Add this to your app.js(express js file)
var path = require('path');
app.set('views', path.join(__dirname, 'views'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
OR this one liner will work
app.use(express.static(__dirname + '/public'));
Next time please use Stackoverflow before posting a issue here 馃槃
There is a usability issue here, though: it looks like @vitalkanev may have installed the module html, but since that module is not an Express template module, it causes this odd error. The error can be made better, though.
Most helpful comment
Try this
npm install ejs --savenpm install path --saveAdd this to your app.js(express js file)
var path = require('path');app.set('views', path.join(__dirname, 'views'));app.engine('html', require('ejs').renderFile);app.set('view engine', 'html');OR this one liner will work
app.use(express.static(__dirname + '/public'));Next time please use Stackoverflow before posting a issue here 馃槃