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

barechat-core

v3.0.0

Published

Core chat functionality for BareChat - reusable P2P networking components

Readme

BareChat Core

Core chat functionality for BareChat - reusable P2P networking components.

Installation

npm install barechat-core

Testing

Run the tests using brittle:

npm test

Usage

import { getBackend } from 'barechat-core'

// Initialize the chat backend
const backend = getBackend({ bootstrap: ['192.168.0.123:55688'] })

// Join or create a chat room
const room = await backend.joinRoom('my-chat-room')

// Send a message
backend.sendMessage('Hello everyone!')

// Listen for incoming messages
backend.swarm.on('connection', (peer) => {
  const memberId = backend.getMemberId(peer)
  console.log(`New peer ${memberId} joined`)
  
  peer.on('data', (rawData) => {
    const event = JSON.parse(rawData)
    console.log(`Message from ${memberId}:`, event.message)
  })
})

API

getBackend(opts)

Initializes the networking layer and returns an object containing the core API functions.

Parameters:

  • opts (Object, optional): Configuration options for the Hyperswarm instance
    • bootstrap (string[], optional): A list of bootstrap servers to use for discovering peers

Returns:

  • createRoom: Function to create a new chat room
  • getMemberId: Function to generate a short identifier for a peer
  • joinRoom: Function to join an existing chat room using a topic string
  • sendMessage: Function to send a message to all connected peers
  • strToTopic: Function to convert a string to a valid topic hash
  • isHashcode: Function to validate if a string is a valid 64-character hex hash
  • swarm: The underlying Hyperswarm instance
  • version: The version of the BareChat package

createMessage(msg, local, messageType)

Creates a message object with timestamp and metadata.

Parameters:

  • msg (string): The content of the message
  • local (boolean, optional): Indicates whether the message is sent from a local device
  • messageType (string, optional): The type of the message (defaults to 'text')

Using BareChat Core as a Package

To create variant chat experiences, you can import barechat-core in your project:

import { getBackend } from 'barechat-core'

const {
  swarm,
  getMemberId,
  createRoom,
  joinRoom,
  sendMessage
} = getBackend()

Example Usage

import { getBackend } from 'barechat-core'

// Initialize the chat backend
const backend = getBackend({ bootstrap: ['192.168.0.123:55688'] })

// Join or create a chat room
const room = await backend.joinRoom('my-chat-room')

// Send a message
backend.sendMessage('Hello everyone!')

// Listen for incoming messages
backend.swarm.on('connection', (peer) => {
  const memberId = backend.getMemberId(peer)
  console.log(`New peer ${memberId} joined`)
  
  peer.on('data', (rawData) => {
    const event = JSON.parse(rawData)
    console.log(`Message from ${memberId}:`, event.message)
  })
})

For detailed API documentation, see the API documentation.

License

MIT