Routing in Express/Node.js using multiple callbacks

I'm new to Node.js, or even JavaScript in general, and I'm currently setting up a http-server using Node/Express that should query a postgresql database. I am unsure if I'm using the routing and multiple callbacks correct, and hope someone can clarify this a bit.

Right now, it looks like this:

In my web.js

var routes = require('./routes');
app.get('/get/user/:userid', routes.user, routes.dbquery);

and in routes/index.js

exports.user = function(request, response, next) {
    request.querystring = "select * from users where userid = " + request.param('userid');
    next();
};

exports.dbquery = function(request, response) {
    pg.connect(process.env.DATABASE_URL, function(err, client, done) {
        var query = client.query(request.querystring);  
        query.on('row', function(row, result) {
            result.addRow(row);
        });
        query.on('end', function(result) {
            response.send(JSON.stringify(result.rows));
        });
        done();
    });
};

It works, but is this the correct way to set up routing? Specifically, is it ok to just pass on variables like the query string inside the request variable? Or is there some other, preferred solution to this?

The reason I want to do it is because I want to be able to reuse the dbquery function, since I will have multiple routes which will query the database.

Yes, you can attach anything you want to request object ( and this is a common practice ). However data there should be related to the request only, while your query is not really related to the request only ( except for userid ).

So how about instead of defining query in middleware just define external function:

var get_query = function(userid) {
    // NOTE: You should validate userid!!!
    return client.query("select * from users where userid = " + userid);
};

and call it in your dbquery route? And only attach userid to request.