npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nghyane/x-api-client

v1.0.3

Published

Twitter/X API client using curl-impersonate for posting tweets with media. Written in TypeScript for Bun runtime.

Downloads

9

Readme

X API Client

Unofficial Twitter/X API client using curl-impersonate for browser impersonation.

Platform Support

  • macOS (Intel & Apple Silicon)
  • Linux (x86_64 & ARM64)
  • ⚠️ Windows (Use WSL2)

Binaries included in bin/curl-impersonate/ - auto-detects your platform.

Installation

bun install

For Windows, use WSL2:

wsl --install
cd /mnt/c/your-project

Quick Start

import { XApiClient } from "./src";

const client = new XApiClient(process.env.X_COOKIE!);

// Post a tweet
const result = await client.post("Hello Twitter! 🚀");
console.log("Tweet URL:", result.url);

API Coverage

📝 Tweets

🔍 Search & Discovery

❤️ Engagement

Usage Examples

Post Tweet with Images

const result = await client.post(
  "Check out this manga! 📚",
  ["./cover.png", "./page1.png"]
);

Reply to Tweet

const reply = await client.reply(
  tweetId,
  "Great post! 👍",
  ["./response.png"]
);

Search Tweets

const results = await client.search.searchTweets({
  query: "manga",
  count: 20,
  product: "Latest", // 'Top' | 'Latest' | 'People' | 'Photos' | 'Videos'
});

for (const tweet of results.tweets) {
  console.log(`@${tweet.authorUsername}: ${tweet.text}`);
}

// Pagination
if (results.cursor) {
  const page2 = await client.search.searchTweets({
    query: "manga",
    count: 20,
    product: "Latest",
    cursor: results.cursor,
  });
}

Get User Profile

const user = await client.users.getUserByScreenName({
  screenName: "elonmusk",
});

console.log(`${user.name} (@${user.username})`);
console.log(`Followers: ${user.followersCount}`);

Home Timeline

const timeline = await client.tweets.getHomeTimeline({ count: 20 });

const instructions = timeline.data?.home?.home_timeline_urt?.instructions || [];
// Parse timeline entries...

See examples/ directory for complete working examples.

Environment Variables

Create a .env file:

X_COOKIE="your_cookie_string_here"

Getting Your Cookie

  1. Open Twitter/X in your browser
  2. Open DevTools (F12) → Network tab
  3. Visit any page (e.g., https://x.com/home)
  4. Find any request → Headers → Copy entire cookie header value
  5. Paste into .env file

Required cookies:

  • auth_token - Your session token
  • ct0 - CSRF token (required!)
  • twid - Twitter user ID

Configuration Options

const client = new XApiClient(cookie, {
  bearerToken?: string;              // Custom bearer (optional)
  language?: string;                 // Default: 'en'
  autoGenerateFingerprint?: boolean; // Default: true
  customHeaders?: Record<string, string>;
});

Error Handling

import { XApiError, AuthError, HttpError, MediaUploadError } from "./src";

try {
  await client.post("Hello!", ["image.png"]);
} catch (error) {
  if (error instanceof AuthError) {
    console.error("Auth failed:", error.message);
  } else if (error instanceof MediaUploadError) {
    console.error("Upload failed:", error.message);
  } else if (error instanceof HttpError) {
    console.error("HTTP error:", error.statusCode);
  }
}

Architecture

src/
├── client.ts              # Main XApiClient
├── core/
│   ├── auth.ts           # Authentication & headers
│   ├── http-client.ts    # curl-impersonate wrapper
│   ├── fingerprint.ts    # Browser fingerprint generator
│   └── transaction/      # Transaction ID generator
├── services/
│   ├── tweet-service.ts       # Tweet operations
│   ├── engagement-service.ts  # Like/Retweet/Delete
│   ├── search-service.ts      # Search tweets/users
│   ├── user-service.ts        # User profiles
│   └── media-uploader.ts      # Image uploads
└── types/                # TypeScript types

Security Notes

⚠️ IMPORTANT:

  • Never commit cookies or tokens to git
  • Add .env to .gitignore
  • Rotate cookies regularly
  • Monitor Twitter's rate limits

Credits & References

This project builds upon research and insights from:

Special thanks to the open-source community for making Twitter/X API research accessible.

License

MIT