Mastodon API client for JavaScript, TypeScript, Node.js, browsers
Examples | Read the Docs | Releases | Issues
npm i masto
- Node.js:
>= 14.x
- TypeScript (optional peer dependency):
>= 3.6.0
- ๐ Isomorphic which means browsers and Node.js are both supported
- โจ๏ธ TypeScript powers static typing. And of course there's no
any
! - ๐ช You don't need to type URLs because each endpoints have their own function
- ๐ Detailed docs and rich hovering menu for IDE, provided by TSDoc
First, open /settings/applications/new
of your instance on your browser and create new application.
Then, here's a simple example that creates a toot. Replace TOKEN
to your own access token.
import { login } from 'masto';
async function main() {
const masto = await login({
url: 'https://example.com',
accessToken: 'TOKEN',
});
await masto.statuses.create({
status: 'Hello Mastodon!',
visibility: 'direct',
});
}
main().catch((error) => {
console.error(error);
});
All of available methods are described in the documentation. You can also refer examples on this repository.
Masto.js validates your Mastodon instance's version to provide more helpful error messages, but this may lead to not working with some Mastodon-compatible software. Therefore, we are offering a way to disable this feature.
await login({
url: "https://example.com",
accessToken: "...",
+ disableVersionCheck: true
});
A. Masto.js is using AsyncIterator which is very new JS feature and it may not be supported in particular environments. So in browsers, you need to use a polyfill like Babel's. In Node.js, it is supported on v10 so you can update and use it.
If you're using Masto.js with TypeScript, you need to add the following config to tsconfig.json
for static typing.
{
"compilerOptions": {
"lib": [
+ "esnext.asynciterable"
...
See CONTRIBUTING.md
Masto.js is distributed under the MIT license