Node router for marketplace routes
Partial application

One way to simplify the code is to eliminate the lambda/anonymous functions using Function.bind() to create Partially applied functions. For instance:


router.get('/online-buyer-count', utils.mcache(15), (req, res, next) =&gt; {
    realTime(DB.onlinebuyerNumQuery, 'onlinebuyerNum', req, res, next);
});



can be simplified to

router.get('/online-buyer-count', realTime.bind(null, DB.onlinebuyerNumQuery, 'onlinebuyerNum'));


And similarly for the other three routes, which reduces 12 lines to 4.

looping over the routes

The redundancy could also be simplified using Array.forEach()

['online', 'offline'].forEach(mode =&gt; { 
    ['buyer', 'seller'].forEach(role =&gt; {
        router.get('/'+mode+'-'+role+'-count', realTime.bind(null, DB[mode+role+'NumQuery'], mode+role+'Num'));
    });
});


Taking that one step further using more partially-applied functions, the callback function of the inner forEach can be pulled out to a separate function:

const addRoute = (mode, role) =&gt; router.get('/'+mode+'-'+role+'-count', realTime.bind(null, DB[mode+role+'NumQuery'], mode+role+'Num'));


And then that function can be made into a partial and used within the nested forEach:

['online', 'offline'].forEach(mode =&gt; ['buyer', 'seller'].forEach(addRoute.bind(null, mode)));


So that can reduce those 4 lines to 2. It may be desirable to break those up into multiple lines for readability.