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

@nullify/libp2p-bundle

v0.2.0

Published

Basic libp2p bundle with settings that match js-ipfs

Downloads

5

Readme

libp2p-bundle

standard-readme

Basic libp2p bundle with settings that match js-ipfs.

This package provides a zero-config setup to make it easy to include a fully- configured libp2p host in any application. It is almost directly copied from js-ipfs, so you can be confident the settings are compatible. It also allows more nuanced access to the underlying libp2p settings.

Table of Contents

Install

npm i @nullify/libp2p-bundle

Usage

import create from "@nullify/libp2p-bundle";

const run = async () => {
  const node = await create({
    multiaddrs: ["/ip4/0.0.0.0/tcp/4007", "/ip4/0.0.0.0/tcp/4008/ws"],
  });

  const p = new Promise((resolve) => {
    // Promise resolves on first discovered peer
    node.on("peer:discovery", (peerId) => {
      resolve(peerId);
    });
  });

  await node.start();

  const listenAddrs = node.transportManager.getAddrs();
  console.log("listening on: ", listenAddrs);

  const peerId = await p;
  console.log(`Discovered: ${peerId.toB58String()}`);
  await node.stop();
  process.exit();
};

run();

API

create(options): Promise<import('libp2p')>

/**
 * @typedef {Object} Repo
 * @property {import('interface-datastore').Datastore} [datastore]
 * @property {import('interface-datastore').Datastore} [keys]
 */

/**
 * @typedef {Object} Options
 * @property {any} [config]
 * @property {import('peer-id')} [peerId]
 * @property {string[]} [multiaddrs]
 * @property {Repo} [repo]
 * @property {{ pass?: string }} [keychainConfig]
 * @property {import('libp2p').Libp2pConfig} options
 */

/**
 * @param {Options} options
 * @returns {Promise<import('libp2p')>}
 */
const create = async ({
  config,
  peerId,
  multiaddrs,
  repo,
  keychainConfig,
  options,
}) => {
  ...
}

The config has defaults for all named options. Usually, you'll only need to follow the usage pattern outlined above. Another common usage pattern is to specify a peerId directly.

import PeerId from "peer-id";
import create from "@nullify/libp2p-bundle";

PeerId.create().then((peerId) => {
  create({
    peerId,
  }).then((node) => {
    node.start().then(() => console.log("node started"));
  });
});

Unlike a default IPFS peer, libp2p-bundle defaults to using an in-memory "repo" for the datastore and keystore. If you want to specify a custom setup (or mimic the IPFS settings), you an simply provide your own datastore- compliant storage config:

import LevelStore from "datastore-level";
import { mkdirSync, existsSync } from "fs";
import { join } from "path";
import create from "@nullify/libp2p-bundle";

// Create a persistent on-disk repo for Nodejs demo
const createRepo = (base) => {
  if (!existsSync(base)) {
    mkdirSync(base);
  }
  return {
    datastore: new LevelStore(join(base, "datastore")),
    keys: new LevelStore(join(base, "keys")),
  };
};

create({
  repo: createRepo("./libp2p"),
}).then((node) => {
  node.start().then(() => console.log("node started"));
});
...

Maintainers

@carsonfarmer

Contributing

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © 2021 Carson Farmer