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-flow-drawer

v0.1.0

Published

A library and CLI for drawning Node-RED flows from JSON files

Downloads

80

Readme

Build Status

Node-RED flow drawer

A library and CLI for drawning Node-RED flows from JSON files.

Table of contents

Prerequisites

  • Node.js 6+

JavaScript API

Installation

npm install node-red-flow-drawer --save

Usage

Source

// index.js
const fs = require("fs");
const FlowDrawer = require("node-red-flow-drawer");
 
const flows = [{"id":"bfc121b1.6847","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"c1f897dd.90a048","type":"http in","z":"bfc121b1.6847","name":"","url":"/in","method":"get","upload":false,"swaggerDoc":"","x":200,"y":540,"wires":[["9b1c0d8f.216f2"]]},{"id":"9b1c0d8f.216f2","type":"http response","z":"bfc121b1.6847","name":"","statusCode":"200","headers":{},"x":500,"y":540,"wires":[]}];

// Optional settings (here are defaults)
const settings = {
    httpNodeRoot: "/",      // Root for http nodes
    userDir: process.cwd()  // A directory with extenal node installations
};

new FlowDrawer(flows, settings)
    .draw("svg")
    .then((images) => {
        for (let image of images) {
            let [, data] = image.split("base64,");
            fs.writeFileSync("output.svg", new Buffer(data, "base64"));
        }
});

Running

node index.js

Output

Output

Settings

  • httpNodeRoot - root for http nodes
  • userDir - a directory with external node installations

CLI

Installation

npm install -g node-red-flow-drawer

Usage

flow-drawer -h

Usage: flow-drawer [options] <inputFileOrDir> [outputDir]

Options:
  -v, --version          output the version number
  -f, --format <format>  export data format (html, json or img) (default: "html")
  -n, --nodes <dir>      path to a directory with installed as npm packages external nodes (CWD by default)
  -s, --stdout           print results to the stdout (only for file input and html/json output)
  -h, --help             output usage information

Batch processing

There are two options for input data:

  • file
  • directory

In the second case CLI searches for all files with .json extension in the directory tree starting from the input folder, tries to draw flows from that files and saves drawnings to the CWD or to the outputDir (if provided).

Export data formats

CLI supports three kinds of export data format:

  • html - all flows save to a single HTML file (useful for previewing)
  • json - all flows save to a single JSON file (with JSON array inside)
  • img - each flow saves to a separate SVG file

Ouputs save to the outputDir (if provided) or to the CWD and name after the input file.

You can use --stdout option (only for html and json formats) to print results to the stdout instead of saving to files.

How to install external nodes

In order to install an external node, you need to install its npm package to a directory and provide the path to the directory as userDir setting in JavaScript API or as --nodes option for CLI.

Known issues:

  • It's not possible to use SVG icons for nodes and to save flows as PNG on Windows (https://github.com/Automattic/node-canvas/issues/1211)
  • Exported images use another font

Troubleshooting

The library depends on node-canvas library. That's why you can face some issues during installation of the library in case if there are no prebuilt binaries for your system. In this case look at Compiling section of node-canvas documentation https://github.com/Automattic/node-canvas#compiling.

Credits

Based on Node-RED 0.19.4.

License

MIT