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 8730205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:58:20+00:00 2026-06-13T08:58:20+00:00

I’m developing a webapp using Node.js and Express. Inside this app, I manage a

  • 0

I’m developing a webapp using Node.js and Express. Inside this app, I manage a stream of JSON data to create a blog reader using Tumblr APIs.

I wrote the route as:

app.get('/blog', function(req, res) {

  var Tumblr = require('tumblr').Tumblr
    , keys = require('./keystore');

  // Instancing Tumblr object to connect with a certain blog.
  var blog = new Tumblr('myblog.tumblr.com', keys.tumblrConsumerSecret);

  // Using Tumblr API to retrieve posts from a remote blog.
  // For more info about methods and parameters to use, read the
  // documentation for Tumblr's API v2.
  blog.posts({offset: 0, limit: 5}, function(err, tumblr) {
    if (err) {
       res.send('Error page... I suppose!');
    }
    else {
      res.render('blog',
      {
        blog: tumblr.posts
      });
    }
  }); 
});

And blog.jade:

each post in blog
  h2 #{post.title}
  .justified
    != post.body

Now, I would like to add numbered page navigation function (as server-side) to the reader.

page 1: posts from 1 to 5
page 2: posts from 6 to 10
(etc...)

What can I do that?

Best regards, Vi.

  • 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-06-13T08:58:21+00:00Added an answer on June 13, 2026 at 8:58 am

    Following chovy’s suggestion, I’ve found a solution.

    In app.js:

    function checkParamPage(req, res, next) {
      if (req.params.page > 0) {
        next();
      }
      else { res.redirect('/error'); }
    }
    
    app.get('/blog/:page', checkParamPage, routes.blog);
    app.get('/error', function(req, res) { res.send('Error!'); })
    

    In routes/index.js:

    exports.blog = function(req, res) {
    
      var _req = req;
      var _res = res;
    
      var Tumblr = require('tumblr').Tumblr
        , keys = require('../keystore')
        , async = require('async');
    
      var page    = req.params.page
        , limit   = 5
        , offset  = page*limit - limit;
    
      // Instancing Tumblr object to connect with a certain blog.
      var blog = new Tumblr('myblog.tumblr.com', keys.tumblrConsumerSecret);
    
      async.parallel([
          function(callback){
            blog.info(function(err, res) {
              if (err) {
                callback('error', null);
              } else {
                callback(null, Math.ceil(res.blog.posts/limit));
              }
            });
          },
          function(callback){
            blog.posts({offset: offset, limit: limit}, function(err, res) {
              if (err) {
                callback('error', null);
              } else {
                if (tumblr.posts.length === 0) {
                  callback('empty', null);
                } else {
                  callback(null, res.posts);
                }
              }
            });
          }
        ], function(err, res) {
          if (err) {
            _res.redirect('/error');
          } else if (page > res[0]) {
            _res.redirect('/error');
          } else {
            _res.render('blog',{
              current: '/blog',
              title: 'MyTitle',
              pages: {
                all: res[0],
                current: page
              },
              posts: res[1]
            });
          }
        }
      );
    };
    

    Then, blog.jade:

    extends layout
    
    block content
    
      // Including sidebar.
      include partials/sidebar
    
      div.span8
        h1 Blog
        hr
    
        each post in posts
          h2 #{post.title}
          div#tumblr-post.justified
            != post.body
          hr
    
        .pagination.pagination-centered
          ul
            if (pages.current > 1)
              li
                a(href='/blog/1') First
            else
              li.disabled
                a(href='/blog/1') First
            - for (var i = 1; i <= pages.all; i++)
              if (i == pages.current)
                li.active
                  a(href='/blog/' + i) #{i}
              else
                li
                  a(href='/blog/' + i) #{i}
            if (pages.current < pages.all)
              li
                a(href='/blog/' + pages.all) Last
            else
              li.disabled
                a(href='#') Last
    
      // Including footer.
      include partials/footer
    

    That’s all (and it works fine)!

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am using Paperclip to handle profile photo uploads in my app. They upload
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.