Wrox Programmer Forums
|
BOOK: Professional Node.js: Building Javascript Based Scalable Software
This is the forum to discuss the Wrox book Professional Node.js: Building Javascript Based Scalable Software by Pedro Teixeira; ISBN: 978-1-118-18546-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Node.js: Building Javascript Based Scalable Software section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2013, 02:38 PM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 21 - 25 - router/middleware setup question

Hello,

I'm trying out the router setup described in Chapters 21 - 25
and I'm getting the following error when running 'nodejs app':

nodejs app

/home/ubuntu/bp3/routes/index.js:8
app.get('/', function(req, res) {
^
TypeError: Cannot call method 'get' of undefined
at /home/ubuntu/bp3/routes/index.js:8:9
at Object.<anonymous> (/home/ubuntu/bp3/app.js:15:26)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:32)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:39)

My app.js and index.js files are included below.

app.js
====


/**
* Module dependencies.
*/

var dbURL = 'mongodb://localhost/database';

var db = require('mongoose').connect(dbURL);


var express = require('express');
require('./routes/index')(app);
require('./routes/users')(app);

var app = module.exports = express.createServer();

// Configuration

app.configure(function(){
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(__dirname + '/public'));
});

app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
app.use(express.errorHandler());
});

// Routes

app.get('/', routes.index);

// app.get('/users:user', routes.users);

app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port,
app.settings.env);
});


routes/index.js
==========


/*
*GET Home Page
*/

module.exports = function(app) {
app.get('/', function(req, res) {
res.render('index', {title: 'Express'})
});
};



Will appreciate your insight on why the above error is being encountered. Thanks!
 
Old May 12th, 2013, 12:39 AM
Registered User
 
Join Date: May 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Answer

express had not been installed properly. The routing worked as expected on installing the 'express' package.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 25 - Shared Data Source Question oviera5 BOOK: Knight's Microsoft Business Intelligence 24-Hour Trainer 0 March 7th, 2012 11:32 PM
Chapter 25 Page 874 Frodo BOOK: Beginning Visual C# 2010 1 January 8th, 2012 04:32 PM
Chapter 25 Code Pankajh_mishra BOOK: Professional C# 2005 with .NET 3.0 ISBN: 978-0-470-12472-7 0 March 18th, 2010 02:44 AM
Missing Chapter 25 cir306 BOOK: Professional Microsoft SQL Server 2008 Programming 0 September 10th, 2009 11:38 PM
Mobile controls setup ch 25 jeffl BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 0 October 13th, 2006 10:12 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.