Reputation:
Error: Failed to lookup view "error" in views directory "/var/www/html/mean/mean-secure1/views" at Function.render (/var/www/html/mean/mean-secure1/node_modules/express/lib/application.js:581:17) at ServerResponse.render (/var/www/html/mean/mean-secure1/node_modules/express/lib/response.js:1008:7) at /var/www/html/mean/mean-secure1/app.js:50:7 at Layer.handle_error (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/layer.js:71:5) at trim_prefix (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:315:13) at /var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:335:12) at next (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:275:10) at /var/www/html/mean/mean-secure1/app.js:39:3 at Layer.handle [as handle_request] (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/layer.js:95:5) at trim_prefix (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:317:13) at /var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:284:7 at Function.process_params (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:335:12) at next (/var/www/html/mean/mean-secure1/node_modules/express/lib/router/index.js:275:10) at SendStream.error (/var/www/html/mean/mean-secure1/node_modules/serve-static/index.js:121:7) at SendStream.emit (events.js:182:13)
app.js
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var bodyParser = require('body-parser');
var morgan = require('morgan');
var mongoose = require('mongoose');
var passport = require('passport');
var config = require('./config/database');
var api = require('./routes/api');
var app = express();
//app.set('view engine', 'pug');
mongoose.Promise = require('bluebird');
mongoose.connect(config.database, { promiseLibrary: require('bluebird') })
.then(() => console.log('connection succesful'))
.catch((err) => console.error(err));
app.use(passport.initialize());
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({'extended':'false'}));
app.use(express.static(path.join(__dirname, 'dist')));
app.use('/books', express.static(path.join(__dirname, 'dist')));
app.use('/api', api);
//app.use(express.static(path.join(_dirname, 'public')));
app.set('views', path.join(__dirname, 'views'));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use(function(err, req, res, next) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};
// render the error page
res.status(err.status || 500);
res.render('error');
});
module.exports = app;
Upvotes: 0
Views: 164
Reputation: 91
If you want to use ejs templating as your view engine then you can use below code to set the view engine for your node application
const ejs=require("ejs");
app.set('view engine','ejs');
Upvotes: 0