Refer in node to flows location / Serve files from flows location

Instead of having my HTML/CSS/JS Files as nodes within my Node Red Flows I want to have them in separate files. My Flows file is versioned in git and it would make sense to have all the other files in git. But I don't see a way to serve HTTP files from the location the flows file is stored (or a sub directory). My flow project should run on Windows as well as on a Raspberry Pi.
Can any give me a hint?
Thank you

What other files?

"HTTP files" are not really a thing! You serve data (files) via HTTP.

To serve "data" from Node-RED you typically use the http-in and http-out nodes. If you want the data that is transmitted to be loaded from a file then simply put a file node between the http-in and http-out. That file can be anywhere (FS permissions permitting)

For example: Download a file from node-red using standard nodes (flow) - Node-RED

Alternatively, you can serve files from by configuring httpStatic - again this can be anywhere (permissions permitting)


Please try to explain a little clearer

My problem is that when I try to specify a full path I don't know what to specify since the directory is different on Windows and Pi. Is there a placeholder that can be used like: %FlowsDirectory%/myfiles/style.css ?

And is that using file nodes or static paths in the settings file?

Please be specific

Sorry for leaving out this information. I would prefer to file nodes approach.

I guess I can't do it in the settings file since this would not switch when switching projects.

Using file nodes defaults to the .node-red directory. Therefore to serve a file named page1.html you would place that file directly alongside the flows.json file and simply put page1.html in the file name field.

Have you tried?

I currently don't remember how it is on the Pi but in Windows the files I refer in the file nodes are expected to be in
C:\Users\[UserName]\AppData\Roaming\npm\.node-red\
But the flows file location is here:
C:\Users\[UserName]\.node-red\projects\[ProjectName]\

Hmmm

I'm speaking from memory but I was certain it would be C:\Users\[UserName]\.node-red\projects\[ProjectName]\

I rarely use project mode so that might be the issue.

However, it is possible to construct a full file path name using env vars etc so you can pass the file name into the file node after dynamically constructing a full path that is x-compatible between Linux/windows - one that essentially points to the path relative to the flows file

Ok, but then I have to configure individual environment variables for each project. Still seems to be the best solution.
Thank you

Not necessarily. Have you inspected the env vars available OOB?

Try putting this in a function node and trigger it from an inject...

node.warn({env: process.env})

You will need to import process on the setup tab.

You might find there is an env var you can use to extrapolate a relative path.

Meanwhile I refactored my project and don't refer to any paths in my nodes. But now I use the httpStatic option in the setting files. Additionally I use the Nunjucks template nodes and added a
nunjucks: { folders: ["..."] } section to the settings file. Unfortunately also this doesn't make sense in my point of view since it cannot be configured per project. But for now I stick with this.
Thank you for all of your hints.

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