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

juncture-server

v2.0.5

Published

A TypeScript module for creating a bridge between React and Node.js applications, enabling graphical user interfaces for Node.js apps with real-time communication

Downloads

4

Readme

Juncture Server

Juncture Server is a TypeScript module that bridges React with Node.js applications, providing graphical user interfaces for Node.js apps. It works in conjunction with the juncture-bridge library to enable seamless communication between frontend and backend.

Features

  • Easy integration with Express server
  • Real-time communication using Socket.IO
  • TypeScript support
  • Can be used in both JavaScript and TypeScript projects
  • Supports both import and require syntax
  • Seamless integration with React via juncture-bridge

Installation

npm install juncture-server

For React integration, also install juncture-bridge:

npm install juncture-bridge

Basic Usage

Setting Up the Server with Default State

You can initialize Juncture with a default state and configuration. Here's an example:

import Juncture from 'juncture-server';

let defaultState = {
    counter: 0,
    message: ""
}

const app = new Juncture(3000, defaultState);

const bridge = app.bridge;

// Backend (Node.js)

// Simple command handler
bridge.registerHandler('greet', async (args) => {
  const greeting = `Hello, ${args.name}!`;
  app.setState({ ...app.getState(), message: greeting });
  return greeting;
});

// Stream example
bridge.registerHandler('count', async (args) => {
  const { countTo } = args;
  for (let i = 1; i <= countTo; i++) {
    app.setState({ ...app.getState(), counter: i });
    bridge.broadcast('counterUpdate', i);
    await new Promise(resolve => setTimeout(resolve, 1000));
  }
  return 'Counting completed!';
});

app.start();

This setup allows you to define a default state and use it in your handlers. The handlers demonstrate how the state is updated and used.

Frontend (React)

First, create a bridge instance:

// utils/bridge.js
import ReactBridge from "juncture-bridge";

const bridge = new ReactBridge("http://localhost:3000");
export default bridge;

Then, use the bridge in your React components:

import React, { useState, useEffect } from 'react';
import bridge from "../utils/bridge";

function App() {
  const [message, setMessage] = useState('');
  const [counter, setCounter] = useState(0);

  const handleGreeting = () => {
    bridge.execute("greet", { name: "World" })
      .then(setMessage)
      .catch(console.error);
  };

  const handleCounting = () => {
    bridge.execute("count", { countTo: 5 })
      .then(console.log)
      .catch(console.error);
  };

  useEffect(() => {
    bridge.on("counterUpdate", (data) => {
      setCounter(data);
    });

    bridge.on("stateUpdate", (newState) => {
      setMessage(newState.message);
      setCounter(newState.counter);
    });

    return () => {
      bridge.off("counterUpdate");
      bridge.off("stateUpdate");
    };
  }, []);

  return (
    <div>
      <button onClick={handleGreeting}>Greet</button>
      <p>{message}</p>
      <button onClick={handleCounting}>Start Counting</button>
      <p>Current count: {counter}</p>
    </div>
  );
}

export default App;

API

Juncture

Constructor

new Juncture(port?: number, defaultState?: any, config?: Partial<JunctureConfig>)
  • port: The port the server will run on (default: 3000)
  • defaultState: Initial state (default: {})
  • config: Configuration options

Methods

  • start(): Starts the server
  • setState(newState: any): Updates the state
  • getState(): Returns the current state

ExpressBridge

Methods

  • registerHandler(command: string, handler: (args: any) => Promise<any>): Registers a new command handler
  • broadcast(event: string, data: any): Broadcasts an event to all connected clients

ReactBridge (from juncture-bridge)

Constructor

new ReactBridge(url: string)
  • url: URL of the Juncture server

Methods

  • execute(command: string, args: any): Promise<any>: Executes a command on the server
  • on(event: string, callback: (data: any) => void): Listens for an event
  • off(event: string): Stops listening for an event

License

MIT