Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > BOOK: Professional Node.js: Building Javascript Based Scalable Software
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 11th, 2013, 02:38 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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!
Reply With Quote
  #2 (permalink)  
Old May 12th, 2013, 12:39 AM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 10:32 PM
Chapter 25 Page 874 Frodo BOOK: Beginning Visual C# 2010 1 January 8th, 2012 03: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



All times are GMT -4. The time now is 06:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.