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

gun-cli

v1.7.1

Published

run gun from your command line

Downloads

53

Readme

gun-cli

DISCLAIMER: WORK IN PROGRESS/NOT PRODUCTION-READY

gun runs a GUN server from your command line

GUN is a distributed, offline-first, realtime graph database engine with built-in encryption. It's a small, easy, and fast data sync and storage system that runs everywhere JavaScript does.

Installation

yarn global add gun-cli     OR     npm install -g gun-cli

Example: Watching an expression

start a local gun peer

gun --host 127.0.0.1 --watch foo.bar

access it from your browser

<html>
	<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
	<script>
		const gun = Gun('http://127.0.0.1:8765/gun')
		gun.get('foo').get('bar').put('baz ' + Date.now())
	</script>
</html>

see foo.bar update in your command line

22:41:50        foo.bar => "baz 1570135310381"

Example: Load and print data from a remote peer

gun print flux.bar --file false --peers 127.0.0.1 --debounce 200 --timeout 2000

This will try to load flux.bar from http://127.0.0.1:8765/gun (extending the provided IP to a full gun URL with the default port 8765). If the query does not resolve within two seconds, the attempt will timeout. However, if the peer can resolve our query, the answers that do come streaming in are debounced with a 200 ms interval, i.e. we try to wait for a full .load() of the data we're interested in.

Example: Using https

ls ./mydomain-certs
> ca.pem cert.pem key.pem

gun --port 443 --certs ./mydomain-certs

Under the hood, this just uses require('https').createServer() with the respective params ca, cert, and key.

Example: Creating a redundant mesh network

Connecting two browsers, A and B, over a mesh of gun peers, 1 through 4

start a small mesh network of gun servers, each listening on a different IP and saving data in a different folder.

gun --host 127.0.0.1 --peers 127.0.0.3,127.0.0.4  --file ./data1 # 1
gun --host 127.0.0.2 --peers 127.0.0.3,127.0.0.4  --file ./data2 # 2

gun --host 127.0.0.3 --peers 127.0.0.1,127.0.0.2  --file ./data3 # 3
gun --host 127.0.0.4 --peers 127.0.0.1,127.0.0.2  --file ./data4 # 4

connect two browsers, A and B, over this network

Browser A

<html>
	<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
	<script>
		const peers = [
			'http://127.0.0.1:8765/gun',
			'http://127.0.0.2:8765/gun'
		]
		const gun = Gun({peers})
		gun.get('foo').get('heartbeat').on(heartbeat => {
			const time = new Date(heartbeat).toLocaleTimeString()
			console.log(`last heartbeat was at ${time}`)
		})
	</script>
</html>

Browser B

<html>
	<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
	<script>
		const peers = [
			'http://127.0.0.3:8765/gun',
			'http://127.0.0.4:8765/gun'
		]
		const gun = Gun({peers})
		setInterval(() => {
			gun.get('foo').get('heartbeat').put(Date.now())
		}, 1000)
	</script>
</html>

now play around with shutting down individual peers and bringing them back online

As long as there is a path through the mesh network, the heartbeats will propagate from B to A.

But if peers 1 and 2 (or peers 3 and 4) simultainiously go down, A and B are seperated and updates won't go through. However, GUN peers will try to reestablish the connection to a lost peer, so as soon as you bring one of the peers back online, they will reconnect and updates will go through again.

Usage

gun [command] [options]

COMMANDS
serve                           [default] start a gun server on http
print NODEPATH                  load NODEPATH and print as JSON
version                         print version numbers and exit

GENERAL OPTIONS
--file PATH         ./gundata/  set file parameter of Gun()
--peers STRING                  comma-seperated list of URLs and IPs
                                (IPs are expanded to http://IP:8765/gun)
--no-color                      do not use any colors in output
--debug                         print GUN debug info
--silent                        reduce command line output
--repl                          go into a repl (with gun instace)

[serve] OPTIONS
--host STRING       0.0.0.0     set the ip to listen on
--port NUMBER       8765        set the port to listen on
--watch PATH                    log changes with gun.path(PATH).on()
--certs PATH        ./certs     use https with cert files from PATH
                                (key.pem, cert.pem, ca.pem)
--nocerts                       disable auto-discovery of ./certs
--webrtc            false       load lib/webrtc

[print] OPTIONS
--out FILENAME                  write to FILENAME instead of stdout
--indent STRING                 indent characters for JSON output
--debounce NUMBER   50          debounce .load() to resolve nested data
                                set to 0 to disable debouncing
--timeout NUMBER    1000        wait this much for answers to your request