Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7012853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:18:35+00:00 2026-05-27T22:18:35+00:00

This is an example of it: // Configuration app.configure(function(){ app.set(‘views’, __dirname + ‘/views’); app.set(‘view

  • 0

This is an example of it:

// 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'));
});

(etc.)

app.get('/memo', function(req, res) {
  console.log("index");
  Memo.find({}, function(err, data) {
    if(err) return next(err);
    res.render('index', { memos: data });
  });
});

And here is another one:

app.get('/memo/list', function(req, res, next) {
  console.log("get memos");
  Memo.find({}, function(err, data) {
    if(err) return next(err);
    res.json(data);
  });
});

Taken from a simple memo pad built on node

These are the questions that are puzzling me:

  1. What does exactly next/next(); do? What would happen if it is not present?
  2. Why is the second part taking next as a parameter and the first isn’t?

EDIT:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:18:36+00:00Added an answer on May 27, 2026 at 10:18 pm

    Express uses middleware functions that have callbacks (functions that get called when an action is completed), and next has that purpose (it’s a callback that triggers the next middleware in the Express stack). All Express middleware (that is Connect compatible) have 3 params: request, response, next (which is optional).

    For example the static middlware serves static files, the csrf middleware checks for a param when receiving POST requests and the router middleware that handles the routes (what you’ve pasted above is part of that).

    Each middleware can complete it’s task and call the next middleware in the queue if some conditions are met (for example the static middleware won’t call a next middleware, because it will take care on itself to serve the files, so that the router won’t get called).

    In the router you don’t usually call next because it tends to be the last middleware executed (unless you want something like benchmarking).

    If you wanted to create a middleware that denies access to all users that aren’t logged in, you would have to call next() only if the user is logged in (so that the next middleware is called, the router in this case and the user can access the page they’re looking for), else you would probably redirect them to the login page.

    next takes either no parameters at all or an error as a parameter.

    Edit: based on your configuration the router is before the static middleware, so if you want files to be served you need to declare a wildcard route that calls next() when the route isn’t matched:

    app.get('*', function (req, res, next) {
      // no route is matched
      // so call next() to pass to the static middleware
      next();
    });
    

    Note: I don’t recommend you put the static file server after the router, I suggest you put it before so you can define your own custom 404 routes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Google app engine task queues have configuration as (example) <queue> <name>mail-queue</name> <rate>5/m</rate> <bucket-size>10</bucket-size> </queue>
I have this Perl script with many defined constants of configuration files. For example:
This example is from php.net: <?php function Test() { static $a = 0; echo
For my app, I have a fairly complex set of configuration options that user
i want to use XML to save some configuration for elements in my app.
I have been trying to work with app.config sections by this example: http://msdn.microsoft.com/en-us/library/system.configuration.configurationcollectionattribute.aspx#Y2391 and
For example in a .NET app.config you might get <configuration> <configSections> <section name=MyConfig type=MyAssembly.MyType,
This example uses a StringWriter to hold the serialized data, then calling ToString() gives
This example is simplified a bit, but in my ASP.NET web page in my
this example below works when hover event is trigered and when its not, its

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.