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 trialjason limmm
8,009 Pointserror is not defined error
app.use((req, res, next)=>{
const error = new Error('uh no!!!! no money for us!!!');
res.status(error.status);
next(error);
});
app.use((err, req, res, next)=>{
res.locals.error = error;
res.render('error', error);
});
the app says that 'error' is not defined i don't know what's the problem
1 Answer
Steven Parker
231,269 PointsIt's not clear what course and lesson you are referring to, but one issue stand out in the code itself. The first function defines "error", but its scope is local to that function only.
The second function tries to reference it (res.locals.error = error
), but it would not be defined at that point.
jason limmm
8,009 Pointsjason limmm
8,009 Pointscan i put the error variable outside both the functions so that it's not only local to one function
something like this
Steven Parker
231,269 PointsSteven Parker
231,269 PointsAnything declared in the global (outside) scope should be available to any function that doesn't shadow it (by having a local variable or parameter of the same name).