javascript - 500 Error: Failed to lookup view "index" in views directory -
i picked book on web development mongodb , node.js. i've come point code not working , feel have correct judging book has. right i'm getting error:
connect 500 error: failed lookup view "index" in views directory "c:\imageuploadproject/views" @ eventemitter.app.render (c:\imageuploadproject\node_modules\express\lib\application.js:555:17) @ serverresponse.res.render (c:\imageuploadproject\node_modules\express\lib\response.js:938:7) @ module.exports.index (c:\imageuploadproject\controllers\home.js:5:7) @ layer.handle [as handle_request] (c:\imageuploadproject\node_modules\express\lib\router\layer.js:82:5) @ next (c:\imageuploadproject\node_modules\express\lib\router\route.js:110:13) @ route.dispatch (c:\imageuploadproject\node_modules\express\lib\router\route.js:91:3) @ layer.handle [as handle_request] (c:\imageuploadproject\node_modules\express\lib\router\layer.js:82:5) @ c:\imageuploadproject\node_modules\express\lib\router\index.js:267:22 @ function.proto.process_params (c:\imageuploadproject\node_modules\express\lib\router\index.js:321:12) @ next >(c:\imageuploadproject\node_modules\express\lib\router\index.js:261:10)
i have index file in specified path. here structure files:
>-controllers >>>+home.js >>>+image.js >-helpers >-node_modules >>>needed modules , such. won't bore ones installed. let me know if there in here see. >-public >-server >>>+configure.js >>>+routes.js >-views >>>-layouts >>>>>>+main.handlebars >>>-partials >>>>>>+comments.handlebars >>>>>>+popular.handlebars >>>>>>+stats.handlebars >>>+image.handlebars >>>+index.handlebars >package.json >server.js
and code files feel might wrong.
server.js
// javascript document var express = require('express'), config = require('./server/configure'), app = express(); app.set('port', process.env.port || 3300); app.set('views', __dirname + '/views'); app = config(app); var server = app.listen(app.get('port'), function() { console.log('server up: http://localhost:' + app.get('port')); }); configure.js // javascript document var path = require('path'), routes = require('./routes'), exphbs = require('express3-handlebars'), express = require('express'), bodyparser = require('body-parser'), cookieparser = require('cookie-parser'), morgan = require('morgan'), methodoverride = require('method-override'), errorhandler = require('errorhandler'); moment = require('moment'); module.exports = function(app) { app.engine('handlebars', exphbs.create({ defaultlayout: 'main', layoutsdir: app.get('views') + '/layouts', partialsdir: [app.get('views') + '/partials'], helpers: { timeago: function(timestamp) { return moment(timestamp).startof('minute').fromnow(); } } }).engine); app.set('view engine', 'handlebars'); app.use(morgan('dev')); app.use(bodyparser({ uploaddir:path.join(__dirname, '.../public/upload/temp') })); app.use(methodoverride()); app.use(cookieparser('some-secret-value-here')); routes.initialize(app, new express.router()); app.use('/public/', express.static(path.join(__dirname, '.../public'))); if('development' === app.get('env')) { app.use(errorhandler()); } return app; };
routes.js
// javascript document var home = require('../controllers/home'), image = require('../controllers/image'); module.exports.initialize = function(app, router) { router.get('/', home.index); router.get('/images/:image_id', image.index); router.post('/images', image.create); router.post('/images/:image_id/like', image.like); router.post('/images/:image_id/comment', image.comment); app.use('/', router); }
home.js
// javascript document module.exports = { index: function(req, res) { res.render('index'); } };
image.js
// javascript document module.exports = { index: function(req, res) { res.render('image'); }, create: function(req, res) { res.send('the image:create post controller'); }, like: function(req, res) { res.send('the image:like post controller'); }, comment: function(req, res) { res.send('the image:comment post controller'); } };
let me know if there other files see. i'm unsure of how proceed here after reviewing book several times. thing can think of there disconnect between express 3.5.x , express 4.0. book covered how convert server.js, configure.js , route.js express 4.0. but, i'm wondering if there did wrong in other files possible not compliant 4.0.
try doing in server.js file
app.set('views', path.join(__dirname, 'views'));
Comments
Post a Comment