Export Instagram followers to CSV with Node.js
To export an Instagram account’s followers with Node.js, call /v1/instagram/users/{user}/followers with the built-in fetch, follow pagination.next_cursor 25 rows at a time and append each page to a CSV. The script below needs Node 18 or newer and no npm packages.
Short answer. Save the script as instagram-followers.mjs, set HANDLEHAUL_API_KEY, run node instagram-followers.mjs natgeo 4 and you get the 100 most recent followers in natgeo_followers.csv. 1,000 followers take 40 calls, $0.056 to $0.032. Public accounts only.
Facts checked 2 December 2026. Prices change: follow the links before you decide.
What you need
- An API key. Sign up and create one in the dashboard. A sandbox key (
kd_test_) returns sample data for free, so you can run the script before you spend anything. - Node.js 18 or newer, for the built-in
fetch. No npm packages: the CSV is written by hand with proper quoting. - The key in
HANDLEHAUL_API_KEY. The script reads it from the environment, so the key never sits in your code or your repository. - Public Instagram accounts. The API returns public data only: no logins, no private accounts, no DMs.
The script
It calls GET /v1/instagram/users/{user}/followers (see the Instagram followers API docs), retries on 429 using Retry-After, and stops with a clear message on any other error. Save it as instagram-followers.mjs.
// Export the followers of a public Instagram account to CSV, newest first.
// Usage: node instagram-followers.mjs <username or numeric id> [max_pages]
// Needs Node 18+ (built-in fetch) and HANDLEHAUL_API_KEY in the environment. No dependencies.
import { writeFileSync, appendFileSync } from "node:fs";
const API = "https://api.handlehaul.com";
const KEY = process.env.HANDLEHAUL_API_KEY;
if (!KEY) fail("Set HANDLEHAUL_API_KEY first, e.g. export HANDLEHAUL_API_KEY=kd_live_...");
function fail(message) {
console.error(message);
process.exit(1);
}
class ApiError extends Error {
constructor(status, code, message) {
super(`HTTP ${status} ${code}: ${message}`);
this.status = status;
this.code = code;
}
}
const sleep = (seconds) => new Promise((resolve) => setTimeout(resolve, seconds * 1000));
// One API call. Waits and retries on 429 (honouring Retry-After) and on 502/503/504,
// throws ApiError for any other error. Failed calls and 429 answers are not charged.
async function get(path, params = {}) {
const url = new URL(API + path);
for (const [k, v] of Object.entries(params)) url.searchParams.set(k, v);
for (let attempt = 0; ; attempt++) {
const res = await fetch(url, { headers: { "X-Api-Key": KEY } });
if ([429, 502, 503, 504].includes(res.status) && attempt < 5) {
const wait = Number(res.headers.get("retry-after")) || 2 ** attempt;
console.error(` HTTP ${res.status}, retrying in ${wait}s`);
await res.arrayBuffer();
await sleep(wait);
continue;
}
const body = await res.json().catch(() => ({}));
if (res.ok) return body;
const err = body.error ?? {};
throw new ApiError(res.status, err.code ?? "unknown", err.message ?? res.statusText);
}
}
// CSV by hand (RFC 4180): quote a cell when it holds a comma, a quote or a line break.
const cell = (v) => {
const s = v == null ? "" : String(v);
return /[",\r\n]/.test(s) ? `"${s.replace(/"/g, '""')}"` : s;
};
const csvLine = (values) => values.map(cell).join(",") + "\r\n";
const FIELDS = ["position", "id", "username", "full_name", "is_private", "is_verified", "profile_pic_url"];
const [user, maxArg] = process.argv.slice(2); // all digits = numeric id; write @12345 for an all-digit username
if (!user) fail("Usage: node instagram-followers.mjs <username or numeric id> [max_pages]");
const maxPages = Number(maxArg ?? 4); // 25 followers a page
const out = `${user.replace(/^@/, "")}_followers.csv`;
const path = `/v1/instagram/users/${encodeURIComponent(user)}/followers`;
writeFileSync(out, "" + csvLine(FIELDS)); // the BOM lets Excel read emoji and accents
let params = {}, pages = 0, rows = 0, credits = 0;
try {
while (pages < maxPages) {
const body = await get(path, params);
pages++;
credits += body.meta.credits_charged ?? 0;
if (body.meta.list_hidden) {
console.log("This account hides its followers from everyone.");
break;
}
if (body.meta.order === "unspecified") console.error(` page ${pages} is not in newest-first order`);
appendFileSync(out, body.data.map((r) => csvLine(FIELDS.map((f) => r[f]))).join(""));
rows += body.data.length;
console.log(`page ${pages}: ${rows} followers`);
if (!body.pagination.has_more) break;
params = { cursor: body.pagination.next_cursor };
}
} catch (e) {
fail(`Stopped: ${e.message}\n${rows} followers saved in ${out}`);
}
console.log(`Saved ${rows} followers to ${out} (${pages} pages, ${credits} credits)`);
node instagram-followers.mjs natgeo 4Run it
- Get an API key. Sign up at api.handlehaul.com/signup and create a key. A sandbox key (
kd_test_) returns sample data for free while you test. - Set HANDLEHAUL_API_KEY. Export the key as the environment variable
HANDLEHAUL_API_KEYso it never sits in the code. - Check Node.js. Run
node --versionand make sure it is 18 or newer, for the built-in fetch. No npm packages are needed. - Save the script as instagram-followers.mjs. Copy the script above into
instagram-followers.mjs. - Run it. Run
node instagram-followers.mjs natgeo 4. Progress prints as it goes; the output file is written as rows arrive, so an interrupted run keeps what it fetched.
export HANDLEHAUL_API_KEY=kd_live_... # your key from the dashboard
node --version # v18 or newer
node instagram-followers.mjs natgeo 4
$env:HANDLEHAUL_API_KEY="kd_live_...".How it works
Paging. Each call to /v1/instagram/users/{user}/followers returns up to 25 followers and a pagination object. The script sends pagination.next_cursor back as ?cursor= until has_more is false or it has read max_pages pages. Cursors are opaque and signed: pass them back unchanged.
Order. position: 1 is the account’s most recent follower, so page one holds the newest rows. meta.order says newest_first; on the rare call where it says unspecified, the script prints a warning. Instagram shares no follow dates with anyone, so there is no “followed at” column.
Hidden lists. When meta.list_hidden is true, the account hides its followers from everyone: the page is empty and the script stops.
One row short. Now and then a page misses one account while the rest stay in order. Never treat an account missing from one run as an unfollow; confirm it over several runs.
Usernames and ids. Naming an account by a handle we have not looked up in the last 7 days adds 1 lookup credit; send the numeric id from any result to skip it. The script takes either: natgeo or 787132. Get the id once from a profile call (or the profiles tutorial) and reuse it.
What it costs
Every successful call is 1 credit, at $1.40 to $0.80 per 1,000 calls. One call per page of 25. Add 1 lookup credit when you name the account by a username we have not looked up in the last 7 days. Pages served from cache are free.
| Job | Calls | Cost |
|---|---|---|
| Newest 100 followers | 4 | $0.0056 to $0.0032 |
| 1,000 followers | 40 | $0.056 to $0.032 |
| 10,000 followers | 400 | $0.56 to $0.32 |
The script makes one call at a time, well under the account limit of 10 to 30 requests per second. Each response says what it cost in meta.credits_charged, and the script adds those up in its last line.
Sample output
An example run with example values, not a real export. Field names and shapes are the ones in the API docs.
page 1: 25 followers
page 2: 50 followers
page 3: 75 followers
page 4: 100 followers
Saved 100 followers to natgeo_followers.csv (4 pages, 4 credits)
position,id,username,full_name,is_private,is_verified,profile_pic_url
1,6860189,new_follower,New Follower,false,false,https://scontent.cdninstagram.com/…
2,3141592,coffee.place,Coffee Place,false,false,https://scontent.cdninstagram.com/…
Common errors
Errors come back as { "error": { "code", "message", "request_id" } } with an HTTP status. Failed calls are never charged. Full list: error codes.
| Status and code | When | What the script does |
|---|---|---|
403 private_account | The account is private | Stops. Private lists are not available. Free. |
404 user_not_found | No account with that username or id | Stops. Free. Check the spelling, or write @12345 for an all-digit username. |
400 invalid_cursor | A cursor from another account or endpoint | Stops. Start again without a cursor. |
401 invalid_api_key | The key is missing, wrong or revoked | Stops with the message. Check the variable with echo $HANDLEHAUL_API_KEY. |
402 insufficient_credits | The account is out of credits | Stops. Rows already fetched stay in the file. |
429 rate_limited | Too many requests per second | Waits for Retry-After and retries, up to 5 times. Not charged. |
502 / 503 / 504 | Data temporarily unavailable or slow | Retries with a growing wait (1, 2, 4, 8, 16 s). Failed calls are free. |
The same job with the SDK
If you would rather not maintain the HTTP code, the official JavaScript SDK (npm install handlehaul) does the paging, retries 429 for you and raises typed errors. The script above is the same job with every request visible.
// npm install handlehaul
import { HandleHaul } from "handlehaul";
const hh = new HandleHaul(); // reads HANDLEHAUL_API_KEY
for await (const user of hh.instagram.followers.iterate("natgeo", { maxPages: 4 })) {
console.log(user.position, user.username);
}
Next steps
- Export Instagram followers to CSV with Python: the same script in Python.
- Instagram followers API: what the endpoint returns and how it compares.
- Instagram followers API docs: every parameter, field and error.
- All tutorials: other jobs on Instagram and TikTok, in Python and Node.js.
Export Instagram followers to CSV with Node.js: questions
Is there an npm package for an Instagram scraper API?
npm install handlehaul installs the official SDK. hh.instagram.followers.iterate() does the paging and the 429 retries for you (see the SDK block above). The script on this page shows the same thing with plain fetch, so you can see every request.Does it work on Node 16 or in the browser?
fetch. Do not run it in a browser: the API key would be visible to anyone. Keep keys on your server.How do I use it from TypeScript?
.mts and run it with a TypeScript runner, or install the SDK, which ships its own types for every response (FollowItem, Profile and so on).Why does the CSV start with an invisible character?
Run it on your own list
One key for Instagram and TikTok. $1.40 to $0.80 per 1,000 calls; failed calls are free.
Want to test first? Sandbox keys are free and unlimited, with sample data in the live schema.