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

mastodon

v1.2.2

Published

Mastodon API client for node

Downloads

4,084

Readme

node-mastodon

Mastodon API Client for node

Installing

npm install mastodon

Usage:

var Masto = require('mastodon')

var M = new Masto({
  access_token: '...',
  timeout_ms: 60*1000,  // optional HTTP request timeout to apply to all requests.
  api_url: 'https://gay.crime.team/api/v1/', // optional, defaults to https://mastodon.social/api/v1/
})

node-mastodon API:

var M = new Masto(config)

Create a Mastodon instance that can be used to make requests to Mastodon's APIs. Currently only supports oauth2 access tokens (no username/password auth) for security reasons.

I advise that you use the oauth package to get the user's access_token. More information about how to do that is on the wiki.
You'll need to register your app on Mastodon first as well.

If authenticating with user context, config should be an object of the form:

{
  access_token: '...'
}

M.get(path, [params], callback)

GET any of the REST API endpoints.

path

The endpoint to hit.

params

(Optional) parameters for the request.

callback

function (err, data, response)

  • data is the parsed data received from Mastodon.
  • response is the http.IncomingMessage received from Mastodon.

M.post(path, [params], callback)

POST any of the REST API endpoints. Same usage as T.get().

M.getAuth()

Get the client's authentication tokens.

M.setAuth(tokens)

Update the client's authentication tokens.


Examples

Reading the home timeline

M.get('timelines/home', {}).then(resp => console.log(resp.data))

Upload an image and attach it to a tweet

var id;
M.post('media', { file: fs.createReadStream('path/to/image.png') }).then(resp => {
  id = resp.data.id;
  M.post('statuses', { status: '#selfie', media_ids: [id] })
})

Advanced

You may specify an array of trusted certificate fingerprints if you want to only trust a specific set of certificates. When an HTTP response is received, it is verified that the certificate was signed, and the peer certificate's fingerprint must be one of the values you specified. By default, the node.js trusted "root" CAs will be used.

eg.

var M = new Masto({
  access_token:         '...',
  trusted_cert_fingerprints: [
    '66:EA:47:62:D9:B1:4F:1A:AE:89:5F:68:BA:6B:8E:BB:F8:1D:BF:8E',
  ]
})