httpStatic and projects

Hi,

I manage a few different projects using the very nice git/projects feature. However, I often always add custom visualizations, so I am wondering, if it is possible to define the httpStatic parameter in the settings.js dynamically?

I think of something like the following in my settings.js:

// settings.js
// ...snip...
module.exports = {
    // ...
    httpStatic: path.join(projectpath, 'static'),
    // ...
}

However, I cannot dig out any variable which provides the current projectpath for the selected git/project (at least not at the time this file is loaded).

The main idea is to keep the project specific static files alongside the other project files and store them in the git repo, too. This would allow:

  • easy switching between different projects (and their visualization/static files) without always additionally changing the settings.js
  • keeping additional files under version control and in sync with the actual project/flows

I've already looked at the other, similar questions (and some answers), but could not find a simple solution.

Thanks,

Holger

I think that is always <userDir>/projects/ though not sure if that helps since there are 2 ways to set the userDir (3 if you count letting node-red do it itself) and I don't think you can retrieve it in settings.js unless you are setting it via an environment variable or not setting it at all.

If not setting the userDir, it will always be in <userHome>/.node-red/ and you can generally get userHome from an OS environment variable (it potentially has different names on different OS's though).

Interesting question though and one that I'd be keen to see some innovative answers to. :slight_smile:


Ah, of course, the default userDir is found with path.join(os.homedir(), '.node-red'), I even have that in my settings.js commented out :smile_cat:

If you were using uibuilder and wanted to have project-specific front-end code, you could do:

...
  uibuilder: {
    uibRoot: path.join(os.homedir(), '.node-red', 'projects', 'uibuilder'),
  },
...
1 Like

Very nice set of hints, thanks!

This would basically help finding the (default) project root folder (as implicit <userDir>/projects/), but is still missing the actual project name...

I guess there is no other way as to dig though the sources and find out how the git integration works (and then get the settings/paths from there)...

Oops, I must have been tired last night to miss that!

If you are running node-red via systemd, you can have a file containing environment variables to be used. So you could, in theory create a flow that you put in the library and add to each new project that sets an env variable in that file and restarts node-red, that would give you access to it.