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

nostr-indexer

v0.1.3

Published

An indexer for nostr events that can be installed as an npm package for your backend projects. It can be used as a backbone to build:

Downloads

3

Readme

WARNING: This project is still under heavy development. There are many features still missing and no security audits have been made. Use at your own risk.

🔍 nostr-indexer

An indexer for nostr events that can be installed as an npm package for your backend projects. It can be used as a backbone to build:

  • Lightweight node for your personal nostr data and social graph.
  • REST / GraphQL / tRPC backend to power a lightweight client application.
  • Event notification system.
  • AI powered content filter (block dic pics)
  • ...?

nostr-indexer abstracts the connections and subscriptions made to relays and provides a simple interface to configure + retrieve data from the indexer. Data is stored in an sqlite database and available to be queried using SQL or built-in functions.

🤷‍♂️ Why?

Almost all nostr clients currently are communicating with relays directly. This can be problematic:

  • Data you care about is not immediately available, when you open most of the existing apps, data trickles in.
  • Background syncing is hard to implement in some cases (eg. web / PWAs) and will put a strain on mobile device's battery life, bandwidth and storage.
  • There is no single source of truth for your data and social graph so your experience on different devices can be inconsistent.
  • Notifications are harder to implement without relying on third parties.
  • Developer experience can be simplified if we can fetch data using common patterns like REST, GraphQL, tRPC...

nostr-indexer will be useful for those who want to build something that can take the computational load of sorting their nostr data, is always on and available on a server (locally or remotely).

🚀 Getting Started

1. Installation

yarn add nostr-indexer

2. Setup Database

DATABASE_URL=file:<FULL_PATH_TO_DB_FILE> npx prisma migrate reset --schema ./node_modules/nostr-indexer/prisma/schema.prisma

Substitute <FULL_PATH_TO_DB_FILE> with the full absolute path to your db file, eg. /my-project/nostr.db

3. Usage

Some vanilla javascript code that you can try putting into a index.js and running with DB_PATH=<FULL_PATH_TO_DB_FILE> node index.js

(async () => {
  const nostr = require('nostr-indexer')

  /** @type {import('nostr-indexer').Indexer} */
  // Create the indexer, passing in the path to the database
  const nostrIndexer = nostr.createIndexer({
    dbPath: process.env.DB_PATH,
    // debug: true
  })

  // Add relays
  nostrIndexer.relayManager.addRelay("wss://nostr.fmt.wiz.biz")
  nostrIndexer.relayManager.addRelay("wss://jiggytom.ddns.net")

  // Start
  nostrIndexer.start()

  /** @type {import('nostr-indexer').Account} */
  // Add an account to index
  const account = await nostrIndexer.accountManager.addAccount({
    pubkey: "63c3f814e38f0b5bd64515a063791a0fdfd5b276a31bae4856a16219d8aa0d1f"
  })

  setInterval(async () => {
    // Metadata is logged every second. If any changes get published to one of the relays,
    // the indexer will pick them up and they will be reflected here.
    console.log("Metadata:", await account.getMetadata())
  }, 1000)
})();

Projects

Example projects using nostr-indexer:

Contributions

Contributions are welcome! If you build anything with this library please make a pull request to include a link to it.

Roadmap

  • [x] Add relay.
  • [x] Add account.
  • [x] Index metadata.
  • [ ] Emit event when new data is indexed.
  • [ ] Allow event to be consumed with a listener or callback.
  • [ ] Index followers + n.
  • [ ] Index DMs.
  • [ ] Index notes.
  • [ ] Index channels.