Handling <settings.userDir>/package.json when using the Storage APIs

Hi @knolleary , @dceejay

As I re-implement the Cloudant file storage on the latest Docker image, I am wondering how it should handle the package.json file used internally to manage modules installed. In the standard Docker image, the assumption is that /data is persistent and therefore the package.json file will persist over restarts. Using the Cloudant storage means that /data is not persistent and therefore the package.json will need to be recreated from the Cloudant database somehow when the storage subsystem is initialised and then the database will need to be updated every time package.json is updated (I assume when you add nodes to the pallet or a function node).

How do you envisage this being handled for external storage systems without persistent file storage?

For nodes you need to set autoInstallModules in your settings file as we do here for the IBM Cloud app - node-red-app/bluemix-settings.js at master · IBM/node-red-app · GitHub

Then, whenever the runtime restarts it checks the list of modules it expects to be installed (which is stored in runtime settings using whatever storage plugin you are using) and dynamically reinstalls anything that's missing.

It isn't ideal, but it just about works okay.

For the Function node's modules, we don't have an equivalent mechanism. autoInstallModules only applies to the nodes it loaded the last time it started.

This is certainly a gap in the functionality we provide - but I don't have a quick solution for it today. We would have to keep a list in runtime settings of the modules that get loaded and then follow a similar pattern to what we do with node modules.

Hi @knolleary , I have reverted to using the official image on IBM Cloud and I am still getting an error message about a missing package.json every time I install a module from the palette. I haven't yet worked out whether it's just an annoying error message that doesn't affect anything, or whether it stops the newly installed nodes from re-installing. It would be pretty easy to stop the error message by ensuring that the Docker file installs an empty package.json in the userDir (although that probably wouldn't work with Cloud Foundry) but obviously that wouldn't be persistent and I don't know whether that matters or not. If auto-install ignores what's in that package.json then I guess it wouldn't matter that it gets reset every re-deploy of Node-RED.

Longer term, I was wondering whether it would be worth making the <userDir>/package.json persistent by keeping a copy of it in a Cloudant document if you are using cloudantStorage.js, that might help solve the Function node problem. The key would be to finding a way of keeping the Cloudant document in sync with the file, do you think that you could use the postInstall and postUninstall hooks to do that?

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.