relative path for static content (windows)

1,294 views
Skip to first unread message

DoNcK

unread,
Nov 15, 2017, 8:56:15 AM11/15/17
to Node-RED
Hi there,

I have one machine running Node-RED on Windows. When it starts up, it displays the following :

15 Nov 14:21:56 - [info] Node-RED version: v0.17.5
15 Nov 14:21:56 - [info] Node.js  version: v4.4.2
15 Nov 14:21:56 - [info] Windows_NT 10.0.15063 x64 LE
...
15 Nov 14:21:58 - [info] User directory : \Users\donck\.node-red


So I thought I could create a "static" directory under "\Users\donck\.node-red" and edit my settings.js to serve static files

At first I used:

httpStatic: 'C:\\Users\\donck\\.node-red\\static',

That worked, but I didnt like that it was dependent from my OS and username so I wanted to use a relative path:

httpStatic: 'static',
or

httpStatic: './static',

But that does NOT work


I ended up using:

var path = require("path"); // <--- prepend this line to settings.js
httpStatic: path.join(process.env.HOMEPATH,".node-red","static"),

(path.join returns "\Users\donck\.node-red\static")


Is there a simpler way to use a relative path for static stuff that would also work on Windows machines ?


Best regards


DoNcK

Nick O'Leary

unread,
Nov 15, 2017, 8:58:22 AM11/15/17
to Node-RED Mailing List
The only alternative is, if you want it relative to the settings file without making any assumptions about where the settings file is, you can do:

   httpStatic: path.join(__dirname,"static")


Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/7bb978e7-5bbb-4722-8bcc-ffbe81bd463f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

DoNcK

unread,
Nov 15, 2017, 9:01:43 AM11/15/17
to Node-RED
Exactly what I needed, thanks Nick !

DoNcK

Julian Knight

unread,
Nov 16, 2017, 4:02:53 AM11/16/17
to Node-RED
if you are wanting to get easy access to msg's from/to Node-RED to go with your static served files, you can also use node-red-contrib-uibuilder. Adding a uibuilder node creates a folder for you and gives you access to a websocket connection specific for that folder and any sub-folders.

On Wednesday, 15 November 2017 13:56:15 UTC, DoNcK wrote:
Hi there,
Reply all
Reply to author
Forward
0 new messages