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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fostrom

v0.0.17

Published

Fostrom's Official Device SDK for JS. Fostrom (https://fostrom.io) is an IoT Cloud Platform.

Readme

Fostrom Device SDK

Fostrom is an IoT Cloud Platform built for developers. Monitor and control your fleet of devices, from microcontrollers to industrial IoT. Designed to be simple, secure, and fast. Experience first-class tooling with Device SDKs, type-safe schemas, programmable actions, and more.

The Fostrom Device SDK for JavaScript works in Node.js and Bun, on Linux and macOS, and helps you quickly integrate, start monitoring, and controlling your IoT devices in just a few lines of code.

Example

import Fostrom from 'fostrom';

const fostrom = new Fostrom({
  fleet_id: "<fleet-id>",
  device_id: "<device-id>",
  device_secret: "<device-secret>",
})

// Setup the on_mail handler, to process incoming mail.
fostrom.onMail = async (mail) => {
  const {id, name, payload, mailbox_size} = mail
  console.debug(`Received Mail (${mailbox_size}): ${name} ${id}`)

  // You need to call `mail.ack()` to acknowledge the mail.
  // Other options are: `mail.reject()` and `mail.requeue()`
  // Note that if your function throws an error, the SDK will auto-reject the mail.
  await mail.ack()
}

async function main() {
  await fostrom.start()

  // Send a message to Fostrom (payload can be null if schema has no payload)
  await fostrom.sendMsg("<packet-schema-name>", { /* ...payload */ })

  // Send a datapoint to Fostrom
  await fostrom.sendDatapoint("<packet-schema-name>", { /* ...payload */ })
}

main()

Requires Node.js 22.12+ or Bun 1.2+

You can load the SDK via either syntax:

import Fostrom from 'fostrom'
const { default: Fostrom } = require('fostrom')

A Note on BigInts

Fostrom's Packet Schemas support defining u64 and i64 integers. However, JavaScript's Number type is limited to 2^53 - 1. To rectify this issue, we use the bigint type and handle JSON encoding and decoding automatically.

Note that there's a caveat here. When Fostrom delivers a message to the SDK containing a u64 or i64 number, it will convert to the Number type if it is smaller than 2^53 - 1, and convert to bigint if it is larger. This is because the SDK does not know if the field is a u64 or i64 type when converting. So for those fields you will need to check whether the type is bigint or not.

A Note on the Device Agent

The Fostrom Device SDK downloads and runs the Fostrom Device Agent in the background. The Agent is downloaded when the package is installed through npm. The Device Agent starts when fostrom.start() is called and handles communication with the Fostrom platform.

By default, the agent remains running in the background for fast reconnections. The SDK also installs a process exit handler; fostrom.shutdown() is called automatically on process exit, and if stopAgentOnExit is set to true in the config, the agent is stopped as well.

Logging

By default, the SDK logs connection and handler messages to the console. Set log: false in the constructor config to silence SDK logs. Levels used:

  • console.info for successful connection events
  • console.warn for reconnection attempts
  • console.error for unauthorized/critical errors