Member-only story

How to add pagination to 3rd party API (26 lines of code!)

Jonas K
2 min readDec 12, 2020

--

Even though this example require Node.js, you don’t have to be afraid if you only got frontend experience. This requires minimal Javascript knowledge.

I once wanted to fetch an open third party API, which consisted of 150.000 objects. This took about 30 seconds to get response - which made it more or less useless for me, as a frontend developer. I want to share with you, how I solved it with minimal Node experience.

So to get started, we will setup a Node project and install express, node-fetch and cors.

mkdir node-pagination
cd node-pagination
npm init
npm install express node-fetch cors
touch index.js

Now open the project with your favourite editor.

First of all, go to your package.json file and add start to your scripts.

"scripts": {
"start": "node index.js"
}

That is all we have to change in package.json

Now go to index.js file and add

const express = require("express");
const fetch = require("node-fetch");
const cors = require("cors");
const app = express();
app.use(cors())let data = null;
let url = "https://jsonplaceholder.typicode.com/albums/1/photos";

--

--

Jonas K
Jonas K

Written by Jonas K

Building stuff on the world wide web. Hi👋

No responses yet