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

deskthing-server

v0.10.3

Published

The Deskthing connector for the server apps

Downloads

553

Readme

DeskThing Server NPM

The DeskThing-App Server is an essential module for setting up your DeskThing App. It provides the server-side communication layer for your app.

Deskthing-Server is intended to work alongside DeskThing-Client to allow communication back-and-forth with the client. DeskThing-Server holds all the information and functions the server/ side of your app needs.

Installation

To install the server, use the following command:

npm install deskthing-server

Usage

Initializing the DeskThing Server

To use the DeskThing server in your application, you need to import it and get an instance:

import DeskThing from 'deskthing-server';

const deskThing = DeskThing.getInstance();

Sending Messages to the Client

You can send messages to the client using the sendDataToClient method. For example, to send a JSON object to the client:

deskThing.sendDataToClient({type: 'message', payload: 'Hello, Client!'});

Receiving Messages from the Client

To handle incoming messages from the client, you need to set up event listeners:

deskThing.on('data', (data) => {
console.log('Received data:', data);
});

Example: Two-Way Communication

Here is a more complete example demonstrating two-way communication between the server and client:

Server Side

import DeskThing from 'deskthing-server';

const deskThing = DeskThing.getInstance();

// Sending a message to the client
deskThing.sendDataToClient({ type: 'message', payload: 'Hello, Client!'});

// Listening for a response from the client
deskThing.on('data', (data) => {
    console.log('Received data from client:', data.payload); // will print "someResponse" in this example
});

deskThing.on('set', (data) => {
    console.log('Received data from client:', data.payload.key); // will print 'value' in this example
});

Client Side

import DeskThing from 'deskthing-client';

const deskThing = DeskThing.getInstance();

// Sending a message to the server
deskThing.sendMessageToServer({ type: 'set', payload: { key: 'value' } });

// Listening for a response from the server
deskThing.on('message', (data) => {
    console.log('Received response from server:', data); // logs 'Hello, Client!'
    deskThing.sendMessageToServer({type: 'data', payload: 'someResponse'})
});

Additional Features

Sending Data to Other Apps

You can route requests to another app running on the server:

deskThing.sendDataToOtherApp('appId', { type: 'set', payload: { key: 'value' } });

Fetching Data from the Server

To fetch persistent data from the server:

const data = await deskThing.getData();
console.log('Fetched data:', data);

Managing Settings

To manage settings:

const settings = await deskThing.getSettings();
console.log('Current settings:', settings);

Background Tasks

To add a background task:

const taskLoop = () => {
// Your background task code
return true;
};

deskThing.addBackgroundTaskLoop(taskLoop);

Additional Information

You can find more information in https://github.com/itsriprod/deskthing-app-client