A module to interact with the Twitter API
npm install twttrapi-middlewareA 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
``bash`
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.
Set your RapidAPI key as an environment variable:
`bash`
export RAPID_API_KEY="your-rapidapi-key"
Optionally, enable debug mode:
`bash`
export DEBUG=true
`typescript
import TwttrApi from "twttrapi-middleware";
// Get instance (singleton pattern)
const twttr = TwttrApi.getInstance();
// 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));
`
Returns the singleton instance of the TwttrApi class.
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.
`bashInstall dependencies
npm install
MIT © dcSpark