npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

masto

v6.10.1

Published

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

Downloads

17,878

Readme

Features

  • 🌎 Universal: Works in Node.js, browsers, and Deno
  • 📦 Lightweight: Less runtime codes, 6kB+ minified and gzipped
  • 📚 TypeScript: Written in TypeScript, and provides type definitions
  • 🧪 Tested: 100% test coverage using a real Mastodon server
  • 🤓 Maintained: Actively maintained by a Fediverse lover since 2018

Migration Guides

Who's using Masto.js?

Quick Start

In this quick start, we'll look at how to create a simple Mastodon bot that publishes a post using Masto.js.

First, you must install Node.js and npm in your environment. Follow the npm official guide for the setup, and proceed to the next step. Alternatively, you can use yarn, pnpm, or other package managers to install Masto.js.

The minimal required version of dependencies is as follows:

  • Node.js: >= 18.x
  • npm: >= 9.x
  • TypeScript (optional peer dependency): >= 5.0.0

If you successfully installed Node.js and npm, create your first Masto.js project with the following command. Assume you're using a POSIX-compatible operating system.

Create a directory and initialise your project.

npm init --yes
npm pkg set type=module

Make sure a package.json file is created in your project directory. Then install Masto.js using npm

npm install masto

Now you successfully initialised your project for developing a Mastodon bot. Next, you need to create an application to obtain an access token required to access your account.

Go to your settings page, open Development, and click the New Application button to obtain your personal access token.

A screenshot from "New application" page from a setting page of Mastodon. It contains three input fields "Application name" "Application website" and "Redirect URI" and checkboxes named "Scopes".

You need to fill out Application name, but rest of the fields can be left as defaults. What you need to select for Scopes is depending on your bot's ability, but you can access most of the functionality by granting read and write. See OAuth Scopes documentation for further information.

Once you have created an application, save Your access token securely. This string is required to access your account through Masto.js.

Then you're almost there! Create a file named index.js inside your project directory and add the following code. This is an example which will post a status from your account.

import { createRestAPIClient } from "masto";

const masto = createRestAPIClient({
  url: process.env.URL,
  accessToken: process.env.TOKEN,
});

const status = await masto.v1.statuses.create({
  status: "Hello from #mastojs!",
});

console.log(status.url);

Finally, run the program with the following command. Replace {URL} with your instance's URL such as https://mastodon.social, and {TOKEN} to your access token that you obtained in the previous section.

URL={URL} TOKEN={TOKEN} node ./index.js

You can learn about other available features in the documentation. You may also want to refer examples to see more examples. Of course, you can ask questions in the Discussions if you have any.

Enjoy your Mastodon development with Masto.js!

Contribution

See CONTRIBUTING.md

License

Masto.js is distributed under the MIT license