A lightweight Node.js client for interacting with Mastodon instances.
This library implements a curated set of Mastodon API methods, allowing you to authenticate, fetch timelines, post statuses, and manage accounts.
- Node v20
$ npm install$ npm testTo create a tarball that you can install in another project:
$ npm packThen in another Node.js project:
$ npm install mastodon-api-x.x.x.tgzIn your package.json, reference the local tarball:
"dependencies": {
...
"mastodon-api": "file:./lib/mastodon-api-x.x.x.tgz"
...
},Import the MastodonAPI class and create a new client by providing your Mastodon access token and instance URL (for example, https://mastodon.social).
import { MastodonAPI } from "mastodon-api";
const api = new MastodonAPI({
accessToken,
instanceURL,
});
// Confirm access token is valid
const { id, username, followers_count, following_count } =
await api.apps.verifyCredentials();This request returns information about the authenticated account and confirms that the provided access token has the required permissions.
MIT