Answer the question
In order to leave comments, you need to log in
Why is the paginate object not visible?
I followed the example on github: https://github.com/expressjs/express-paginate
1. There is a router.js file in which:
var User = require('../app/models/user');
var paginate = require('express-paginate');
....
app.get('/users', function (req, res) {
User.paginate({}, req.query.page, req.query.limit, function(err, pageCount, users, itemCount) {
if (err) return next(err);
res.format({
html: function() {
res.render('userss', {
page: 'users',
users: users,
pageCount: pageCount,
itemCount: itemCount
});
},
json: function() {
// inspired by Stripe's API response for list objects
res.json({
object: 'list',
has_more: paginate.hasNextPages(req)(pageCount),
data: users
});
}
});
});
});
...
// app/models/user.js
// load the things we need
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
// define the schema for our user model
var userSchema = mongoose.Schema({
facebook : {
id : String,
token : String,
name : String,
},
....
photoMax: String,
imgurl: String,
name: String,
score: Number,
about: String,
contacts: String,
});
userSchema.plugin(require('mongoose-paginate'));
.....
// create the model for users and expose it to our app
module.exports = mongoose.model('User', userSchema);
Answer the question
In order to leave comments, you need to log in
Perhaps it
// keep this before all routes that will use pagination
app.use(paginate.middleware(10, 50));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question