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

fmp-js

v0.0.13

Published

The **Fogu** library is a Node.js client for communicating with **Fogu servers** over TCP connections, providing real-time messaging, channels, acation, teams, and event handling.

Readme

Fogu Library Documentation (fmp-js)

Overview

The Fogu library is a Node.js client for communicating with Fogu servers over TCP connections, providing real-time messaging, channels, acation, teams, and event handling.


Installation & Import

import { Fogu, fogu } from 'fmp-js';

// Or create a new instance explicitly:
const client = Fogu();

Main Class: Fogu

Connecting to the Server

// Connection URL format: fmp://username:password@host:port
await client.connect('fmp://user:pass@localhost:4222');

// Connection events
client.on('connected', () => {
  console.log('Connected to server');
});

client.on('error', (err) => {
  console.error('Connection error:', err);
});

client.on('close', () => {
  console.log('Connection closed');
});

Primary Methods

connect(url: string): Promise<void>

Establishes a connection to a Fogu server.

channel(name: string): FoguChannel

Creates and returns a channel instance with the given name.

team(name: string): OneTeam

Creates and returns a team/group instance.

close(): void

Closes the active connection.

Properties

  • id: string – Client ID assigned by the server
  • connected: boolean – Connection state

Class: FoguChannel

Channel Management

const channel = client.channel('my-channel');

// Create channel
await channel.create('Channel description');

// Update description
await channel.edit('New description');

// Remove channel
await channel.remove();

// Retrieve channel info
const info = await channel.info();

Publishing & Subscribing

Publish Messages

await channel.publish('my-topic', Buffer.from('Example message'));

Subscribe to Topics

await channel.subscribe('my-topic', (topic, message) => {
  console.log(`Received on topic ${topic}:`, message.toString());
});

acation & calls

Create a action

await channel.action('my-action', (message, reply) => {
  const response = Buffer.from('action response');
  reply(null, response);          // Success
  // reply(new Error('action error')); // Error
});
await channel.service([{
  name:'my-action',
 handle: (message, reply) => {
    const response = Buffer.from('action response');
    reply(null, response);          // Success
    // reply(new Error('action error')); // Error
  },
  info:""
}]);

Make a call

try {
  const response = await channel.call(
    'my-action',
    Buffer.from('call payload'),
    5000 // timeout (ms)
  );

  console.log('Response:', response.toString());
} catch (error) {
  console.error('call error:', error);
}

Query Methods

// List available acation
const acation = await channel.getacation();

// List events
const events = await channel.getEvents();

// List accessible channels
const channels = await channel.list();

Specialized Sub-channels

// WebSocket bridge
channel.ws().emit('event', Buffer.from('data'));

// MQTT bridge
channel.mqtt().publish('topic', Buffer.from('message'));

// Redis interface
channel.redis().set('key', Buffer.from('value'));

// Device APIs
channel.device();

// Application APIs
channel.app();

// Script APIs
channel.script();

Class: OneTeam

Team Management

const team = client.team('my-team');

// Create team
await team.create();

// Update team
await team.edit();

// List teams
await team.list();

// Remove team
await team.remove();

Member Management

const member = team.member();

// Add member
await member.create();

// Update member
await member.edit();

// List members
await member.list();

// Remove member
await member.remove();

Team Channel Management

const teamChannel = team.channel();

// Attach channel to team
await teamChannel.connect('channel-name');

// Detach channel
await teamChannel.disconnect('channel-name');

// List connected channels
await teamChannel.list();

Server Message Handling

Supported Server Commands

  • INFO – Server information and client identification
  • MSG – Published topic messages
  • CH_REQ – Incoming action call
  • RES / AUTH / CH_RES – call response frames
  • OK – Operation acknowledgement
  • ERROR – Server-side errors
  • PING / PONG – Connection keep-alive

Complete Usage Example

import { Fogu } from 'fmp-js';

async function example() {
  const client = Fogu();

  try {
    // Connect
    await client.connect('fmp://user:pass@localhost:4222');

    // Create channel
    const channel = client.channel('example-channel');
    await channel.create('Example channel');

    // Subscribe
    await channel.subscribe('notifications', (topic, message) => {
      console.log(`Notification: ${message.toString()}`);
    });

    // Define a action
    await channel.action('calculator', (data, reply) => {
      const n = parseInt(data.toString(), 10);
      const result = n * 2;
      reply(null, Buffer.from(result.toString()));
    });

    // Publish message
    await channel.publish('notifications', Buffer.from('Hello world!'));

    // Make call
    const response = await channel.call('calculator', Buffer.from('5'), 3000);
    console.log(`Result: ${response.toString()}`); // "10"

  } catch (error) {
    console.error('Error:', error);
  } finally {
    client.close();
  }
}

example();

Error Handling

The library uses Promises and callback-based error handling:

try {
  await channel.publish('topic', payload);
} catch (error) {
  console.error('Publish failed:', error.message);
}

// action callbacks
channel.action('my-action', (message, reply) => {
  try {
    reply(null, result);
  } catch (error) {
    reply(error); // Sends error frame to caller
  }
});

Timeouts

All call operations support timeouts:

const response = await channel.call('action', data, 5000);

Buffer as Data Format

All data is transmitted as Buffers, giving full freedom over payload format:

// Text
Buffer.from('Simple text', 'utf8');

// JSON
Buffer.from(JSON.stringify({ key: 'value' }));

// Binary data
Buffer.from(arrayBuffer);