npm

Need private packages and team management tools?Check out npm Orgs. »

masto

2.5.4 • Public • Published

Mastodon API client for JavaScript, TypeScript, Node.js, browsers

npm

Installation

npm i masto

Requirements

  • Node.js: >= 10.x
  • TypeScript (optional peer dependency): >= 3.5.x

Basic Usage

First, fetch your access token through the following command. DO NOT publish the token.

$ npx masto-cli token --uri=URI --email=EMAIL --password=PASSWORD

Then, here's a simple example that creates a toot. Replace TOKEN to your own token.

// For Node.js
const { Masto } = require('masto');
// For Babel, TypeScript, Webpack, Parcel
import { Masto } from 'masto';
 
(async () => {
  const masto = await Masto.login({
    uri: 'https://example.com', // URL of your instance
    accessToken: 'TOKEN', // Your access token (optional)
  });
 
  const data = await masto.createStatus({
    status: 'Hello Mastodon!',
    visibility: 'direct',
  });
 
  console.log(data);
})();

All of available methods are described in the documentation. You can also refer examples on this repository.

FAQ

Q. What is the deference between Masto.js and the others?

  • 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
  • AsyncIterator makes timeline pagination easier.

Q. I got an error Symbol.asyncIterator is not defined

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"
      ...

Contribution

See CONTRIBUTING.md

License

GNU Affero General Public License v3

Keywords

install

npm i masto

Downloadsweekly downloads

25

version

2.5.4

license

AGPL-3.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability