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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kukei/mastodon-api

v1.0.0

Published

Mastodon API toot posting library

Downloads

187

Readme

@kukei/mastodon-api

A lightweight, no-dependency, limited library for posting statuses to Mastodon.

Used by Kukei.eu and masto.kukei.eu to post updates and threads to Mastodon instances. Will be maintained until I maintain those two.

Features

  • Send toots
  • Reply to toots (or use as threads poster)

Installation

npm install @kukei/mastodon-api
yarn add @kukei/mastodon-api

Quick Start

import { MastodonApi } from '@kukei/mastodon-api';

// Initialize the client
const mastodon = new MastodonApi({
  token: 'your-mastodon-access-token',
  url: 'https://mastodon.social' // or your Mastodon instance URL
});

// Post a status
const statusId = await mastodon.sendStatus(
  'Hello, Mastodon! 👋',
  'en'
);

console.log(`Status posted with ID: ${statusId}`);

API Reference

new MastodonApi(options)

Creates a new Mastodon API client.

Parameters

  • options (Object):
    • token (string, required): Your Mastodon access token
    • url (string, required): The URL of your Mastodon instance (e.g., https://mastodon.social)
    • fetch (function, optional): Custom fetch implementation (defaults to globalThis.fetch)

Example

const mastodon = new MastodonApi({
  token: 'your-access-token',
  url: 'https://mastodon.social'
});

mastodon.sendStatus(text, language, replyTo)

Posts a status to Mastodon.

Parameters

  • text (string, required): The content of your status
  • language (string, required): The language code (e.g., 'en', 'es', 'fr')
  • replyTo (string, optional): The ID of the status you're replying to (default: null)

Returns

  • Promise<string>: The ID of the posted status

Examples

Post a simple status:

const statusId = await mastodon.sendStatus(
  'Hello, world!',
  'en'
);

Reply to a status:

const replyId = await mastodon.sendStatus(
  'Great post!',
  'en',
  '109876543210' // ID of the status you're replying to
);

Post in different languages:

// Spanish
await mastodon.sendStatus('¡Hola, mundo!', 'es');

// French
await mastodon.sendStatus('Bonjour le monde!', 'fr');

// Japanese
await mastodon.sendStatus('こんにちは世界!', 'ja');

Idempotency

The library automatically generates an idempotency key based on the status text using MD5 hashing. This prevents duplicate posts if you accidentally send the same request twice. The same text will always generate the same idempotency key.

Error Handling

The library throws an error if the API request fails:

try {
  const statusId = await mastodon.sendStatus('Hello!', 'en');
  console.log('Success:', statusId);
} catch (error) {
  console.error('Failed to post status:', error.message);
}

Advanced Usage

Custom Fetch Implementation

You can provide a custom fetch implementation, which is useful for testing or when using in environments without a built-in fetch:

import fetch from 'node-fetch'; // or any fetch polyfill

const mastodon = new MastodonApi({
  token: 'your-token',
  url: 'https://mastodon.social',
  fetch: fetch
});

Development

Running Tests

npm test

Running Tests with Coverage

npm run coverage

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.