Tutorial · Instagram · Node.js

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.

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)`);
Tested 2026-12-02 against the documented API responses on Node.js 26, using only Node 18 features. Run: node instagram-followers.mjs natgeo 4

Run it

  1. 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.
  2. Set HANDLEHAUL_API_KEY. Export the key as the environment variable HANDLEHAUL_API_KEY so it never sits in the code.
  3. Check Node.js. Run node --version and make sure it is 18 or newer, for the built-in fetch. No npm packages are needed.
  4. Save the script as instagram-followers.mjs. Copy the script above into instagram-followers.mjs.
  5. 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.
Terminal
export HANDLEHAUL_API_KEY=kd_live_...   # your key from the dashboard
node --version                  # v18 or newer
node instagram-followers.mjs natgeo 4
On Windows PowerShell, set the key with $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.

Calls and cost for export instagram followers to csv
JobCallsCost
Newest 100 followers4$0.0056 to $0.0032
1,000 followers40$0.056 to $0.032
10,000 followers400$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.

Terminal
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)
natgeo_followers.csv
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.

Errors this script can meet and what it does
Status and codeWhenWhat the script does
403 private_accountThe account is privateStops. Private lists are not available. Free.
404 user_not_foundNo account with that username or idStops. Free. Check the spelling, or write @12345 for an all-digit username.
400 invalid_cursorA cursor from another account or endpointStops. Start again without a cursor.
401 invalid_api_keyThe key is missing, wrong or revokedStops with the message. Check the variable with echo $HANDLEHAUL_API_KEY.
402 insufficient_creditsThe account is out of creditsStops. Rows already fetched stay in the file.
429 rate_limitedToo many requests per secondWaits for Retry-After and retries, up to 5 times. Not charged.
502 / 503 / 504Data temporarily unavailable or slowRetries 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.

Node SDK
// 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);
}
Source and reference: handlehaul-js on GitHub.

Next steps

Export Instagram followers to CSV with Node.js: questions

Is there an npm package for an Instagram scraper API?
Yes: 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?
It needs Node 18 or newer for the built-in 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?
Rename the file to .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?
That is a UTF-8 byte order mark. It makes Excel read emoji and accented names correctly. Most CSV readers skip it; remove the "\uFEFF" part of the script if yours does not.

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.