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

decene

v0.0.15

Published

Framework for creating decentralised distributed p2p networks.

Downloads

19

Readme

Work in progress

For real.

Usage

Short version

See repository hexagon/decene-examples```

A little longer version

Fairly complete and minimal example of how to use decent... Untested code!

const 
    { network, encryption } = require("decene"),
    fs = require('fs'); // fs is used to read/write registry cache to disk

// Settings
let idLocation = '~/.decene.id';
let cacheLocation = "~/.decene.registy";

// Try to load identity from cache, or create a new identity
let id = encryption.loadIdentity(idLocation);
if (!id) {
    // Create
    id = encryption.newIdentity(idLocation);
    if (!id) {
        console.log("Could not read or create identity, bailing out.");
        process.exit(0);
    } else {
        console.log("New identity generated and stored at " + cacheLocation);
    }
} 

// Try to load registry cache
let cache;
try {
    cache = JSON.parse(fs.readFileSync(cacheLocation, 'utf8'));
} catch (err) {
    console.error('Warning: Could not load cache.');
}

// Set up network client, listen at 0.0.0.0:47474, use my.decent.spawn.address.fake:47474 as "spawn" in case no local cache is available
var d = new network(id,"0.0.0.0","47474","my.decent.spawn.address.fake:47474",cache);

// Handle network events
d.events.on('state:changed',(prevState,curState) => {
    console.log("State changed: "+prevState+" -> "+curState);
});
d.events.on('server:error', (err) =>        console.error("Server Error:"+err));
d.events.on('socket:error', (err) =>        console.error("Socket Error:"+err));
d.events.on('error', (err) =>               console.error("Generic Error:"+err));

d.events.on('server:listening', (port) =>   console.log("Listening at " + port));
d.events.on('ip:changed',(ip) =>            console.log("Public ip verified: "+ip));

// A message is received (could be core, or application specific message)
d.events.on('message:received', (message, socket) => {
    if (message.type) {
        let hasPayload = message.payload ? "yes" : "no";
        console.log(message.type + ' > payload : ' + hasPayload);
    }
});

// A unhandled message is received this is an invalid, or application specific message
d.events.on('message:unhandled', (message, socket) => {
    if (message.type === "mycustommessage") {
        let hasPayload = message.payload ? "yes" : "no";
        console.log("Custom message received > payload : " + hasPayload);
    }
});

// Handle registry events
d.events.on('node:discover', (node) => {    console.log('Discover: ' + node.uuid );  });

// Handle registry disk cache
d.events.on('registry:batch', (node) => {
    fs.writeFile(cacheLocation, JSON.stringify(d.reg.serialize()), err => {
      if (err) {
        gui.log.log("Registry cache flush failed: " + err);
        return;
      } else {
        gui.log.log("Registry cache flushed to disc");
      }
    })
});

Development

  1. Clone decene adjacent to your reference project, using decent-examples
cd my-projects-folder
git clone ..../decene
git clone ..../decene-examples
  1. Edit the decene imort in the reference project, example
// Local decene development using adjacent dir
var {network, encryption } = require("../../decene/lib"),

// Normal mode, using decene from npmjs
// var {network, encryption } = require("decene"),
  1. Build decene, to generate lib folder from typescript code
cd decene
npm run-script build
  1. Run your reference project, now you are using the local version of decene

  2. When you are ready to commit to decene, make sure everything is formatted, linted, tested and do build

npm run-script format
npm run-script lint
npm run-script test
npm run-script build

git add .
git commit -m "Yay, committing working and tested code."