Express: Why is next() "not defined" inside the app.all route function?

Created on 23 May 2013  Â·  8Comments  Â·  Source: expressjs/express

I'm doing this:

app.all("*", function(req, res) {
    console.log("\n\n------------- BLAH ---------\n\n");
    next(); // Why doesn't next() work here????????
});

And it says "ReferenceError: next is not defined" so I can't move to the next route.

Why?

Most helpful comment

The next function is passed in as the 3rd param of the callback. You need to give it a name:

app.all('*', function(req, res, next) {
...

On May 23, 2013, at 12:16 PM, trusktr [email protected] wrote:

I'm doing this:

app.all("*", function(req, res) {
console.log("\n\n------------- BLAH ---------\n\n");
next(); // Why doesn't next() work here????????
});
And it says "ReferenceError: next is not defined" so I can't move to the next route.

Why?

—
Reply to this email directly or view it on GitHub.

All 8 comments

The next function is passed in as the 3rd param of the callback. You need to give it a name:

app.all('*', function(req, res, next) {
...

On May 23, 2013, at 12:16 PM, trusktr [email protected] wrote:

I'm doing this:

app.all("*", function(req, res) {
console.log("\n\n------------- BLAH ---------\n\n");
next(); // Why doesn't next() work here????????
});
And it says "ReferenceError: next is not defined" so I can't move to the next route.

Why?

—
Reply to this email directly or view it on GitHub.

Btw, I'd suggest you to learn JavaScript before you try to go on with express

@brainflake Oops, my brain flaked. That was obvious, and I'm tired from final exams at school. I'll remember that next time!

@Nami-Doc Forgetting to pass an argument to a function is (for the most part) language-independent and it doesn't have much to do with JavaScript. For all you know, I might be better at JavaScript than you are, but I could care less if I am.

I hope you are, I think I'm a pretty bad javascripter myself. But the error seems to be self-explanatory enough, so I thought you were just "trying to get express running" - don't take offense. I spend quite some time on stackoverflow and this happens a lot : you want a better technology than the one you're currently stuck with, but sometimes you just didn't learn the host langage enough (ie: rails server-side, or ... jquery haha).

is (for the most part) language-independent

To a certain extent ... A lot of langages have most of their libraries with global state.

nevertheless i think its a bad idea to tell people to stop doing what they are doing to learn something,
even if its well intended advice.

if somebody wants to learn anything the best approach to self taught learning imho is to have a project.
it might end up badly implemented, it might not be usable at all,
but having a goal is the most important part of learning to me and most self taught people in the hackspaces i know.

dont take this as a personal attack, as said its just my humble opinion.

keep on rocking you all,
<3, have fun
jascha

@Nami-Doc None taken, and my tone was simply matter-of-factly with no anger. :D We are always learning. parseInt(), for example, is global, so using next() like that could be legitimate, but if I'd thought long enough, and had more sleep, I might've realized that next() isn't global. Node.js doesn't allow a require()ed module to set a global property in the namespace where it is require()ed.

@manarius, Yeah, I agree with the project thing. I learned that way more so than taking tutorials.

Cheers.

nevertheless i think its a bad idea to tell people to stop doing what they are doing to learn something,
even if its well intended advice.

more like "know what you're gonna have to deal with", of course I wouldnt recommend learn another library or something in the middle of trying express

Haha yeah, one milestone at a time is probably best.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sunriselegacy picture Sunriselegacy  Â·  3Comments

cuni0716 picture cuni0716  Â·  3Comments

extensionsapp picture extensionsapp  Â·  3Comments

zackarychapple picture zackarychapple  Â·  3Comments

gaurav5430 picture gaurav5430  Â·  3Comments