Node.js client for Twitter API
⚠️ Important notice
Twitter now has an official TypeScript SDK.
We recommend using that instead of this client.
This project will be maintained, but will not be developed any further.
To all contributors who added to this project: Thank you 🧡
Table of content
Features
☑️ Includes 90% of the official Twitter API endpoints.
☑️ Promise-based! No ugly callbacks.
☑️ Fully typed! Both for query parameters and responses.
☑️ Inbuilt in-memory cache for rate-limit friendly usage.
Getting Started
You will need to create a set of Twitter developer credentials from your Twitter Developer account.
If you don't have one already, apply for a developer account here.
It takes about 5 minutes.
Install
npm i twitter-api-client
Usage
import { TwitterClient } from 'twitter-api-client';
const twitterClient = new TwitterClient({
apiKey: '<YOUR-TWITTER-API-KEY>',
apiSecret: '<YOUR-TWITTER-API-SECRET>',
accessToken: '<YOUR-TWITTER-ACCESS-TOKEN>',
accessTokenSecret: '<YOUR-TWITTER-ACCESS-TOKEN-SECRET>',
});
const data = await twitterClient.accountsAndUsers.usersSearch({ q: 'twitterDev' });
const data = await twitterClient.directMessages.eventsShow({ id: '1234' });
const data = await twitterClient.tweets.statusesRetweetsById({ id: '12345', count: 25 });
const data = await twitterClient.trends.trendsAvailable();
See all available methods here.
Configuration
twitter-api-client
comes with an inbuilt in-memory cache.
The stale data is served by the cache-first principle.
You can configure the caching behavior upon instantiation of the client:
const twitterClient = new TwitterClient({
apiKey: '<YOUR-TWITTER-API-KEY>',
apiSecret: '<YOUR-TWITTER-API-SECRET>',
accessToken: '<YOUR-TWITTER-ACCESS-TOKEN>',
accessTokenSecret: '<YOUR-TWITTER-ACCESS-TOKEN-SECRET>',
ttl: 120,
disableCache: true,
maxByteSize: 32000000,
});
License
This project is licensed under the MIT License
Get Help
Contribute
Issues
In the case of a bug report, bugfix or a suggestions, please feel very free to open an issue.
Pull request
Pull requests are always welcome, and I'll do my best to do reviews as fast as I can.
Please refer to the contribution guide to see how to get started.