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

phant-client

v1.0.1

Published

Node Phant Client

Downloads

8

Readme

iotdb-phant-client

Node Client for Phant.

Usage

To connect to data.sparkfun.com

var Phant = require('phant-client').Phant
var phant = new Phant()

To connect to your own Phant server:

var phant = new Phant({ "iri": "http://localhost:8080" })

IMPORTANT NOTE

If you are using your own Phant server, you must be running phant-manager-http. Make sure you follow the instructions in the README.md on this page:

https://github.com/sparkfun/phant-manager-http

Creating a new stream

Functions create() and connect() will callback with a streamd object which can be used to do Phant stuff. You must create() or connect() to a Phant server first: you can't just use a serialized streamd object.

phant.create({
    title: "My Awesome Stream",
    description: "The description",
    fields: "a,b,c"
}, function(error, streamd) {
    if (error) {
        console.log("+ error", error)
    } else {
        console.log(streamd)
    }
}

Connecting to an existing stream

Note that if the stream as created on a different Phant server, it will work exactly as expected. The streamd records the location of the server it connected to.

phant.connect(streamd, function(error, streamd) {
    /* do stuff */
})

Connecting to an IRI

If you have a 'streams' IRI, you can connect directly to that

var iri = 'https://data.sparkfun.com/streams/dZ4EVmE8yGCRGx5XRX1W'
phant.connect(iri, function(error, streamd) {
    /* do stuff */
})

Adding a record

phant.add(streamd, {
    a: 22
})

Phant requires that all fields be present. iotdb-phant-client cleverly defaults these to the empty string.

Retrieving the latest record

Note that this is entirely independent of the next/reset functions below.

phant.latest(streamd, function(error, rd) {
    if (error) {
        console.log("# error", error)
    } else if (rd === null) {
        console.log("+ eof")
    } else {
        console.log("+ got", rd)
    }
})

Stepping through stream

The first class to next() will get the first record and subsequent calls will step through the data. When no more data is available, null will be returned to indicate EOF. If you want to start looping through the records again from the beginning, call phant.reset(streamd). If you need to loop through records multiple times simultaneously, use phant.scrub(streamd) to return a copy of the stream object.

The sightly complicated nature of this example is because the code is callback driven.

var fetcher = function() {
    phant.next(streamd, function(error, rd) {
        if (error) {
            console.log("# error", error)
        } else if (rd === null) {
            console.log("+ eof")
        } else {
            console.log("+ got", rd)
            fetcher()
        }
    })
}

fetcher()