Can we install a module and a storage module in node-red user directory

Hello,

I have an issue with storage plugin and node module local installation.

I have written:

  • a node-red-contrib-postgres-storage module meant to be used as a storageModule
  • a node-red-contrib-flow-metadata module that contains a Node-RED node

Both are still in development, so I'd like to be able to install both locally.

My issue is:

  • If I install only node-red-contrib-flow-metadata in ~/.node-red this way:

C:\Users\Admin.node-red> npm install node-red-contrib-flow-metadata

Then it works as expected, i.e. the new node is available in the palette, and node-red-contrib-flow-metadata is displayed underneath node-red in User Settings > Palette > Nodes

  • if I install only node-red-contrib-postgres-storage in ~/.node-red this way:

C:\Users\Admin.node-red> npm install C:\workspace\node-red-contrib-postgres-storage --install-links

Then it works as expected, i.e. if I add this line to C:\Users\Admin.node-red\settings.js:

storageModule: require("node-red-contrib-postgres-storage"),

Then Node-RED uses the storage module as expected.

  • But if I install both node-red-contrib-postgres-storage and node-red-contrib-flow-metadata in ~/.node-red, the storage still works, but the new node does not show up in the palette anymore, and node-red-contrib-flow-metadata is not displayed in User Settings > Palette > Nodes anymore

If I uninstall node-red-contrib-postgres-storage from ~/.node-red, then node-red-contrib-flow-metadata works again.

Has anyone had this issue before ? Should I raise an issue on the node-red GitHub ?

Thanks,

Romain

As these are both nodes written by you... is there a chance you have duplicated a bunch of scaffolding code into both, such that they have duplicate names/functions/properties , and are clashing with each other ?

Thanks for your suggestion, that's a good idea. However I've double checked, and everything seems different. I haven't created one from the other, or even both from the same template (I created the storage module from another one I found on the Node-RED library, and I created the node module from the "first node" template on the Node-RED web site ( Creating your first node : Node-RED ).

After you run the npm install command each time, check the contents of ~/.node-red/package.json. Check your modules are being added to the dependencies section of that file.

With both installed:

  • do you get any error messages in the node-red log when you start node-red?
  • check the contents of ~/.node-red/.config.nodes.json - search it for any mention of your contrib-flow-metadata node. Is it there? If so, does it have an error property?

Also are your nodes somewhere we can look at them, e.g. github?

Thanks for your suggestion.
Starting from a fresh Node-RED install, ~/.node-red/package.json is clean:

{
    "name": "node-red-project",
    "description": "A Node-RED Project",
    "version": "0.0.1",
    "private": true
}

If I install my node module:

PS C:\Users\Admin\.node-red\node_modules> npm install C:\workspace\node-red-contrib-flow-metadata --install-links

added 1 package, and audited 2 packages in 4s

found 0 vulnerabilities

package.json now contains the dependency:

    "dependencies": {
        "node-red-contrib-flow-metadata": "file:../../../workspace/node-red-contrib-flow-metadata"
    }

Node-RED starts with no error in its output, and I can see the new node in the palette.

If I then install the storage module:

PS C:\Users\Admin\.node-red\node_modules> npm install C:\workspace\node-red-contrib-postgres-storage --install-links

added 16 packages, and audited 18 packages in 8s

found 0 vulnerabilities

The dependency is added in package.json:

    "dependencies": {
        "node-red-contrib-flow-metadata": "file:../../../workspace/node-red-contrib-flow-metadata",
        "node-red-contrib-postgres-storage": "file:../../../workspace/node-red-contrib-postgres-storage"
    }

Node-RED starts with no error in its output, the storage plugin works as expected, but I cannot see my new node any longer.

There is indeed a mention of the metadata module in ~/.node-red/.config.nodes.json, but no error:

    "node-red-contrib-flow-metadata": {
        "name": "node-red-contrib-flow-metadata",
        "version": "0.0.1",
        "local": true,
        "user": true,
        "nodes": {
            "metadata-edit": {
                "name": "metadata-edit",
                "types": [
                    "metadata-edit"
                ],
                "enabled": true,
                "local": true,
                "user": false,
                "module": "node-red-contrib-flow-metadata",
                "file": "\\Users\\Admin\\.node-red\\node_modules\\node-red-contrib-flow-metadata\\metadata-edit.js"
            }
        }
    }

Note that if I uninstall node-red-contrib-flow-metadata from ~/.node-red, and install it there instead:

C:\Users\Admin\AppData\Roaming\npm> npm install C:\workspace\node-red-contrib-flow-metadata

added 1 package

Then it all works fine - the storage plugin works as expected, and I can also see the new node brought by the node-red-contrib-flow-metadata module.

I'm not sure that is something I can do, as the modules are owned by the company I work for. Regarding the module that contains a node (contrib-flow-metadata), I was having this issue even when it was as simple as the node-red-contrib-example-lower-case from the Node-RED tutorial ( Creating your first node : Node-RED). The storage module is very similar to gingerhelp/node-red-contrib-mysql-storage-plugin: Node Red MySQL Storage Plugin.

OK, can you share just the package.json files from them both. I'm mainly interested in if the storage module has a node-red section/

Also while you've said there are no errors in the startup log, could you please post it.

Sure:

  • the storage module:
{
  "name": "node-red-contrib-postgres-storage",
  "version": "0.0.1",
  "description": "Node-RED Storage Plugin For Postgres",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "node-red",
    "postgres"
  ],
  "bugs": {
    "url": ""
  },
  "dependencies": {
    "pg": "^8.13.1",
    "when": "3.7.8"
  },
  "devDependencies": {
    "eslint": "^6.8.0",
    "eslint-config-node": "^4.0.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-plugin-import": "^2.20.1",
    "eslint-plugin-node": "^11.0.0",
    "eslint-plugin-prettier": "^3.0.1",
    "minimist": ">=1.2.2",
    "prettier": "^1.17.0"
  }
}

  • the node module:
{
  "name": "node-red-contrib-flow-metadata",
  "version": "0.0.1",
  "description": "This node module contains nodes that offer an interface to a flow meta-data.",
  "main": "metadata-edit.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "node-red" : {
    "nodes": {
      "metadata-edit": "metadata-edit.js"
    }
  }
}

The startup log:

13 Dec 16:19:40 - [stor] Initializing storage module
13 Dec 16:19:40 - [stor] Getting settings
13 Dec 16:19:40 - [info] 

Welcome to Node-RED
===================

13 Dec 16:19:40 - [info] Node-RED version: v4.0.5
13 Dec 16:19:40 - [info] Node.js  version: v22.11.0
13 Dec 16:19:40 - [info] Windows_NT 10.0.17763 x64 LE
13 Dec 16:19:42 - [info] Loading palette nodes
13 Dec 16:19:45 - [stor] Saving settings
13 Dec 16:19:45 - [info] Settings file  : C:\Users\Admin\.node-red\settings.js
13 Dec 16:19:45 - [info] Context store  : 'default' [module=memory]
13 Dec 16:19:45 - [stor] Getting flows
13 Dec 16:19:45 - [stor] Getting credentials
13 Dec 16:19:45 - [warn] 

---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.

If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.

You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------

13 Dec 16:19:45 - [info] Server now running at http://127.0.0.1:1880/
13 Dec 16:19:45 - [info] Starting flows
13 Dec 16:19:45 - [info] Started flows
13 Dec 16:19:45 - [stor] Getting sessions

(I have added the [stor] logs in the storage plugin)

I have checked and I confirm that I am having this issue even with a node module as simple as the lower-case example from the "Creating your first node" section of the Node-RED website.

That node module is as simple as these three files:

  • lower-case.html:
<script type="text/javascript">
    RED.nodes.registerType('lower-case',{
        category: 'function',
        color: '#a6bbcf',
        defaults: {
            name: {value:""}
        },
        inputs: 1,
        outputs: 1,
        icon: "file.svg",
        label: function() {
            return this.name||"lower-case";
        }
    });
</script>

<script type="text/html" data-template-name="lower-case">
    <div class="form-row">
        <label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
        <input type="text" id="node-input-name" placeholder="Name">
    </div>
</script>

<script type="text/html" data-help-name="lower-case">
    <p>A simple node that converts the message payloads into all lower-case characters</p>
</script>
  • lower-case.js
module.exports = function(RED) {
    function LowerCaseNode(config) {
        RED.nodes.createNode(this,config);
        var node = this;
        node.on('input', function(msg) {
            msg.payload = msg.payload.toLowerCase();
            node.send(msg);
        });
    }
    RED.nodes.registerType("lower-case",LowerCaseNode);
}
  • package.json:
{
  "name": "node-red-contrib-example-lower-case",
  "version": "1.0.0",
  "main": "lower-case.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "description": "",
  "node-red" : {
	"nodes": {
		"lower-case": "lower-case.js"
	}
  }
}

My storage plugin is pretty simple as well:

  • package.json:
{
  "name": "node-red-contrib-postgres-storage",
  "version": "0.0.1",
  "description": "Node-RED Storage Plugin For Postgres",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "node-red",
    "postgres"
  ],
  "dependencies": {
    "pg": "^8.13.1",
    "when": "3.7.8"
  }
}

  • index.js:
const when = require('when');
const Promise = when.promise;
const {
    Pool
} = require('pg');

const storageModule = {
...
// implementation of init, getFlows, saveFlows...
...

};

module.exports = storageModule;