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

node-red-contrib-data-uri

v1.0.1

Published

A Node-RED node to generate a data URI containing specified data

Downloads

13

Readme

node-red-contrib-data-uri

A Node-RED node to generate a data URI containing specified data

Install

Run the following npm command in your Node-RED user directory (typically ~/.node-red):

npm install node-red-contrib-data-uri

Support my Node-RED developments

Please buy my wife a coffee to keep her happy, while I am busy developing Node-RED stuff for you ...

Node usage

Data URI basics

A Uniform Resource Identifier (URI) is a unique path to a web resource (web page, image, document, ...). A client can use such a URI to get a resource from a web server:

URI flow

However in some cases it is not possible to use an URI:

  • It is not desired to make the resource public available on the internet, because the content should not be accessible for everybody (for privacy reasons).
  • The resource should only be temporary available, until the client has fetched the resource.
  • ...

In those cases a data URI might be a solution. A data URI contains the entire (base64 encoded) content of the resource:

data:<some media type>;base64,<base64 encoded resource data>

When such a data URI is passed to a client, the client will simply decode the base64 encoded data inside the URI (instead of accessing an external resource on a remote webserver).

Example flow

The following example flow injects a string "Hello Node-RED" into this node::

example flow

[{"id":"e747f20b1b43678a","type":"data-uri-generator","z":"fa4e3e80.f097b","inputField":"payload","outputField":"payload","format":"text","name":"","x":560,"y":2800,"wires":[["e8e197a30af793c1"]]},{"id":"212e6dfaa8adcabd","type":"inject","z":"fa4e3e80.f097b","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello Node-RED","payloadType":"str","x":360,"y":2800,"wires":[["e747f20b1b43678a"]]},{"id":"e8e197a30af793c1","type":"debug","z":"fa4e3e80.f097b","name":"Data URI","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":740,"y":2800,"wires":[]}]

The output message will contain the data URI "data:text/plain;base64,SGVsbG8gTm9kZS1SRUQ=". Our input text will be included into this url as a base64 encoded text.

It is very easy to check whether the data URI contains the input text, by pasting this generated data URI into the address bar of your browser. The browser will show the input text into the page window:

Browser test

Alternatives

Note that - when dealing with images - the node-red-contrib-image-tools also allow you to create a data URI.

Node properties

Input field

The input message field that contains the data (as buffer or string), that needs to be included inside the data uri.

Output field

The output message field where the generated data uri will be stored. When the output message field is identical to the input message field, then the data in the input message field will be overwritten by the data URI.

Format

The format of the input data, which needs to be specified as a simple file extension. For example the png format will result automatically in mime type image/png.

The mime DB offers a complete overview of all available file extensions. The file extension is available in the "extensions" property. For example the "txt" file extension will result in the "text/plain" mime type (= media type):

"text/plain": {
    "source": "iana",
    "compressible": true,
    "extensions": ["txt","text","conf","def","list","log","in","ini"]
}

But it is easier to work with file extensions (compared to mime types), because you use file extensions on a daily basis ...