A Node.js module to interact with the Twitter API via RapidAPI's twttrapi service. This middleware provides a simplified interface for accessing Twitter data without directly using the official Twitter API.
- Get tweet by ID
- Get user tweets, replies, and media
- Search tweets (latest and top results)
- Search users
- Get user profile information
- Get user followers and following lists
npm install twttrapi-middleware
You need a RapidAPI key with access to the twttrapi service. Sign up at RapidAPI and subscribe to the twttrapi service.
import TwttrApi from "twttrapi-middleware";
// Initialize with your RapidAPI key
const twttr = new TwttrApi('your-rapidapi-key', true); // Second parameter enables debug mode
// Example: Get a tweet by ID
twttr.getTweetById('1907254694163980405')
.then(tweet => console.log(tweet))
.catch(error => console.error(error));
// Example: Get a user's tweets
twttr.getUserTweets('username')
.then(tweets => console.log(tweets))
.catch(error => console.error(error));
new TwttrApi(rapidapiKey: string, debug: boolean = false)
rapidapiKey
: Your RapidAPI keydebug
: Optional boolean to enable debug mode (defaults to false)
All methods return a Promise that resolves to the requested data or an error response.
getTweetById(id: string)
: Get a tweet by its IDgetUserTweets(username: string)
: Get tweets from a usergetUserReplies(username: string)
: Get replies from a usergetUserMedia(username: string)
: Get media tweets from a usersearchTop(query: string)
: Search top tweets for a querysearchLatest(query: string)
: Search latest tweets for a querysearchUsers(query: string)
: Search users by querygetUser(username: string)
: Get a user's profile informationgetUserFollowers(username: string)
: Get a user's followersgetUserFollowing(username: string)
: Get accounts a user is following
The module primarily returns Tweet
, User
, and Media
objects or ErrorResponse
if an error occurs.
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run in development mode
npm run dev
MIT © dcSpark