Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialOlu Gbadebo
Courses Plus Student 516 PointsConsole error
When I run the app.js, I get a TypeError message as follows
" TypeError: Cannot read property 'on' of undefined "
and the console points to the '.on' method
" /home/treehouse/workspace/router.js:46
studentProfile.on("error", function(error){
^ "
1 Answer
Erik Nuber
20,629 PointsI believe that on is a jquery method so you would have to have jquery linked in your html file. You can do so either by downloading from api.jquery.com or by a CDN which you can find on the same site under the download section.
Olu Gbadebo
Courses Plus Student 516 PointsOlu Gbadebo
Courses Plus Student 516 PointsProblem still persists. I don't think it's jquery because jquery is not used in NodeJS
Here is my code: '''javascript
var Profile = require("./profile.js"); var renderer = require("./renderer.js");
//2. Handle HTTP route GET / and POST function home(request, response) { //if url == "/" && GET if (request.url == "/") { //show search response.writeHead(200, {'Content-Type': 'Text/plain'}); renderer.view("header", {}, response); response.end("Footer \n"); } } //if url == "/" && POST //redirect to /username
//3. HAndle HTTP route GET /:username function user(request, response){ //if url == "/...." var username = request.url.replace("/", ""); if (username.length > 0) { response.writeHead(200, {'Content-Type': 'Text/plain'});
} //on "error" studentProfile.on("error", function(error){ //show error response.write(error.message + "\n"); response.end("Footer \n"); }); } module.exports.home = home; module.exports.user = user; '''