Skip to content

fetchlayer-dev/twitter-scraper-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter/X Scraper & API Client for JavaScript / TypeScript

npm license types

The official JavaScript & TypeScript SDK for the FetchLayer Twitter/X API.

Search tweets. Get profiles. Pull followers and following lists. Fetch replies. All as clean JSON from a single API — no scraping infrastructure, no proxies, no X developer account.

Open-source SDK, hosted API. This package is MIT-licensed. The API requires a free FetchLayer API key — no subscriptions, no contracts, no lock-in. Pay only for what you use.


Install

npm install @fetchlayer/twitter
pnpm add @fetchlayer/twitter
yarn add @fetchlayer/twitter

Get your API key

  1. Go to fetchlayer.dev
  2. Sign in with your email
  3. Copy your API key from the dashboard

That's it. No credit card. No trial expiration. You get free requests to start, then pay-as-you-go when you need more.

Quick start

import { FetchLayerTwitter } from "@fetchlayer/twitter";

const twitter = new FetchLayerTwitter({
  apiKey: process.env.FETCHLAYER_API_KEY!,
});

// Search Twitter/X for tweets about any topic
const results = await twitter.search({
  query: "best CRM tools",
  product: "Top",
  count: 10,
});

console.log(results);

That's 4 lines to get structured Twitter/X data. No OAuth, no rate-limit wrestling, no $100/month X API bill.


Why use this instead of X's official API

Problem FetchLayer
X API costs $100/mo (Basic) or $5K/mo (Pro) Free tier + pay-per-use
Complex OAuth setup (4 keys to manage) Single API key
Aggressive rate limits (1 req/15s on some endpoints) No rate limits
Follower graph requires Pro tier ($5K/mo) Followers, following, verified followers included
Maintaining scraping infra is a full-time job npm install and done
You need tweets, profiles, AND followers 10 endpoints, one SDK

All methods

const twitter = new FetchLayerTwitter({ apiKey });
Method What it does
twitter.search(params) Search tweets by keyword (Top, Latest, People, Media, Lists)
twitter.getTweetDetail(params) Get a specific tweet by ID
twitter.getTweetReplies(params) Fetch replies to a tweet
twitter.getUserProfile(params) Get user profile, bio, follower count
twitter.getAboutProfile(params) Get extended profile metadata (category, business type)
twitter.getUserTweets(params) Get recent tweets from a user
twitter.getUserReplies(params) Get recent replies from a user
twitter.getFollowers(params) Get accounts following a user
twitter.getFollowing(params) Get accounts a user follows
twitter.getVerifiedFollowers(params) Get verified accounts following a user

Examples

Search tweets

const results = await twitter.search({
  query: "react server components",
  product: "Latest",
  count: 25,
});

for (const tweet of results.results ?? []) {
  console.log(`@${tweet.author?.handle}: ${tweet.text?.slice(0, 100)}`);
  console.log(`  ${tweet.likeCount} likes · ${tweet.retweetCount} retweets`);
}

Get a user profile

const profile = await twitter.getUserProfile({ handle: "openai" });

console.log(`${profile.displayName} (@${profile.handle})`);
console.log(`Followers: ${profile.followersCount?.toLocaleString()}`);
console.log(`Bio: ${profile.description}`);

Get followers

const followers = await twitter.getFollowers({
  handle: "openai",
  count: 50,
});

for (const account of followers.accounts ?? []) {
  console.log(`@${account.handle}${account.followersCount?.toLocaleString()} followers`);
}

Get verified followers

const verified = await twitter.getVerifiedFollowers({
  handle: "levelsio",
  count: 100,
});

console.log(`${verified.accounts?.length ?? 0} verified followers`);

Paginate through results

// Search with pagination
const page1 = await twitter.search({ query: "AI", product: "Latest", count: 50 });

if (page1.cursor) {
  const page2 = await twitter.search({
    query: "AI",
    product: "Latest",
    count: 50,
    cursor: page1.cursor,
  });
}

// Followers pagination works the same way
let cursor: string | undefined;
do {
  const page = await twitter.getFollowers({
    handle: "openai",
    count: 100,
    ...(cursor ? { cursor } : {}),
  });
  cursor = page.cursor;
  // Process page.accounts...
} while (cursor);

TypeScript

All response types are exported. Import them for full type safety:

import type { SearchResponse, Tweet, UserProfile, FollowersResponse } from "@fetchlayer/twitter";

const data: SearchResponse = await twitter.search({ query: "typescript" });

// Fully typed — no `any` anywhere
for (const tweet of data.results ?? []) {
  console.log(tweet.author?.handle); // string | undefined
  console.log(tweet.likeCount);      // number | undefined
}

API Reference

See the FetchLayer Twitter/X API docs for full endpoint reference, parameter details, and response schemas.


License

MIT © 2026 HootCodes LTD

About

Official JavaScript & TypeScript SDK for the FetchLayer Twitter/X API. Search tweets, get profiles, pull followers, fetch replies, all as clean JSON.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages