app.js:
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var index = require('./routes/index');
var newproject = require('./routes/newProject');
var app = express();
// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'ejs');
// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
app.use('/', index);
app.use('/newproject', newproject);
// 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;
index.js
var express = require('express');
var router = express.Router();
/* GET users listing. */
router.get('/', function(req, res, next) {
res.render('index');
});
module.exports = router;
newproject .js
var express = require('express');
var router = express.Router();
var sql = require ('mssql');
router.get('/newproject', function(req, res) {
res.render('newProject');
});
module.exports = router;
newProject.ejs
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
hello
</body>
</html>
and a similar index.ejs in views .
My home directory works ie localhost:3000/
works but when i type
localhost:3000/newproject
it poses the following error :
Error: Failed to lookup view "error" in views directory "F:\project\pcgWebApp\views" at EventEmitter.render (F:\project\pcgWebApp\node_modules\express\lib\application.js:580:17) at ServerResponse.render (F:\project\pcgWebApp\node_modules\express\lib\response.js:971:7) at F:\project\pcgWebApp\app.js:47:7 at Layer.handle_error (F:\project\pcgWebApp\node_modules\express\lib\router\layer.js:71:5) at trim_prefix (F:\project\pcgWebApp\node_modules\express\lib\router\index.js:315:13) at F:\project\pcgWebApp\node_modules\express\lib\router\index.js:284:7 at Function.process_params (F:\project\pcgWebApp\node_modules\express\lib\router\index.js:335:12) at next (F:\project\pcgWebApp\node_modules\express\lib\router\index.js:275:10) at F:\project\pcgWebApp\app.js:36:3 at Layer.handle [as handle_request] (F:\project\pcgWebApp\node_modules\express\lib\router\layer.js:95:5)
anyone know whats going on - ?Please help - have tried doing npm install .
It does work if i place
router.get('/newproject', function(req, res) {
res.render('newProject');
});
in app.js and change router to app.get..