access files locally

2,428 views
Skip to first unread message

Diogo Zanardini

unread,
Sep 26, 2017, 3:35:41 PM9/26/17
to Node-RED
I want to access files that are on the computer where the node-red is.
Which folder should I go to?
for example, show in a HTML the image smiley.gif in te folder:

/home/administrador/.node-red

to do smoetyhing simple like this:
 <img src="smiley.gif" alt="Smiley face" height="42" width="42">

I try
full path, then only the file then other
alternatives in src and get nothong...
what I do wrong?


the log on start is this:

26 Sep 12:00:45 - [info]

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

26 Sep 12:00:45 - [info] Node-RED version: v0.17.5
26 Sep 12:00:45 - [info] Node.js  version: v4.2.6
26 Sep 12:00:45 - [info] Linux 4.4.0-96-generic x64 LE
26 Sep 12:00:45 - [info] Loading palette nodes
26 Sep 12:00:50 - [info] Dashboard version 2.5.0 started at /ui
26 Sep 12:00:52 - [warn] ------------------------------------------------------
26 Sep 12:00:52 - [warn] [rpi-gpio] Info : Ignoring Raspberry Pi specific node
26 Sep 12:00:52 - [warn] ------------------------------------------------------
26 Sep 12:00:52 - [info] Settings file  : /home/administrador/.node-red/settings.js
26 Sep 12:00:52 - [info] User directory : /home/administrador/.node-red
26 Sep 12:00:52 - [info] Flows file     : /home/administrador/.node-red/flows_administrador-HP-Compaq-Pro-6300-MT.json
26 Sep 12:00:52 - [info] Starting flows
26 Sep 12:00:52 - [info] Started flows
26 Sep 12:00:52 - [info] Server now running at http://127.0.0.1:1880/


Nick O'Leary

unread,
Sep 26, 2017, 3:39:39 PM9/26/17
to Node-RED Mailing List
Node-RED doesn't expose your computer's file system... that would be crazily insecure.

In your settings file you can set the httpStatic property to configure a directory on your local machine that should be served up by the runtime.

For example, if you have /home/administrator/.node-red/static/smiley.gif, and you set httpStatic to /home/administrator/.node-red/static, then you will be able to access http://localhost:1880/smiley.gif

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/e40f262e-f054-4c0c-a013-62147deb6172%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Diogo Zanardini

unread,
Sep 26, 2017, 4:38:28 PM9/26/17
to Node-RED
Hi!

I totaly understand and agreed about the security issues to expose the files in computer that way!

But im running node red on a local application... no internet needed...
Im only use node red as GUI in a local project rigth here only in my pc

by the way... some strange is happens ...
in another project Im make a Template node on dashboard to show some imgs using the tag:
<div id = "img01"><img src="/Img1.jpg" height="120px"></div>
And all rigth!
I put the img on that folder:
/home/administrator/.node-red/

And all work fine

but now the img cant
appear

can be some configuration to
httpAdminRoot?...
I read the page:https://nodered.org/docs/configuration
but the things were not clear to me...

have any way to check this!?

Thanks alot!

Colin Law

unread,
Sep 26, 2017, 4:51:36 PM9/26/17
to node...@googlegroups.com
What have you set httpStatic to and where have you put the file?
Preferably copy/paste from settings.file so we can check for typos.
Also make sure the file is actually in the folder you say.

Colin
> --
> 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+u...@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/83014683-823f-4bdc-8c8a-1ed0e1753f28%40googlegroups.com.

Colin Law

unread,
Sep 26, 2017, 4:52:27 PM9/26/17
to node...@googlegroups.com
Oh and meant to say you need to restart node-red after changing settings.

Colin

Diogo Zanardini

unread,
Sep 26, 2017, 5:07:43 PM9/26/17
to Node-RED
okay!
Lets go!

I dont do anaything with the httpStatic...I suppose everything should be in the default...

copy of settings:

/**
 * Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

// The `https` setting requires the `fs` module. Uncomment the following
// to make it available:
//var fs = require("fs");

module.exports = {
    // the tcp port that the Node-RED web server is listening on
    uiPort: process.env.PORT || 1880,

    // By default, the Node-RED UI accepts connections on all IPv4 interfaces.
    // The following property can be used to listen on a specific interface. For
    // example, the following would only allow connections from the local machine.
    //uiHost: "127.0.0.1",

    // Retry time in milliseconds for MQTT connections
    mqttReconnectTime: 15000,

    // Retry time in milliseconds for Serial port connections
    serialReconnectTime: 15000,

    // Retry time in milliseconds for TCP socket connections
    //socketReconnectTime: 10000,

    // Timeout in milliseconds for TCP server socket connections
    //  defaults to no timeout
    //socketTimeout: 120000,

    // Timeout in milliseconds for HTTP request connections
    //  defaults to 120 seconds
    //httpRequestTimeout: 120000,

    // The maximum length, in characters, of any message sent to the debug sidebar tab
    debugMaxLength: 1000,

    // To disable the option for using local files for storing keys and certificates in the TLS configuration
    //  node, set this to true
    //tlsConfigDisableLocalFiles: true,

    // Colourise the console output of the debug node
    //debugUseColors: true,

    // The file containing the flows. If not set, it defaults to flows_<hostname>.json
    //flowFile: 'flows.json',

    // To enabled pretty-printing of the flow within the flow file, set the following
    //  property to true:
    //flowFilePretty: true,

    // By default, credentials are encrypted in storage using a generated key. To
    // specify your own secret, set the following property.
    // If you want to disable encryption of credentials, set this property to false.
    // Note: once you set this property, do not change it - doing so will prevent
    // node-red from being able to decrypt your existing credentials and they will be
    // lost.
    //credentialSecret: "a-secret-key",

    // By default, all user data is stored in the Node-RED install directory. To
    // use a different location, the following property can be used
    //userDir: '/home/nol/.node-red/',

    // Node-RED scans the `nodes` directory in the install directory to find nodes.
    // The following property can be used to specify an additional directory to scan.
    //nodesDir: '/home/nol/.node-red/nodes',

    // By default, the Node-RED UI is available at http://localhost:1880/
    // The following property can be used to specifiy a different root path.
    // If set to false, this is disabled.
    //httpAdminRoot: '/admin',

    // Some nodes, such as HTTP In, can be used to listen for incoming http requests.
    // By default, these are served relative to '/'. The following property
    // can be used to specifiy a different root path. If set to false, this is
    // disabled.
    //httpNodeRoot: '/red-nodes',

    // The following property can be used in place of 'httpAdminRoot' and 'httpNodeRoot',
    // to apply the same root to both parts.
    //httpRoot: '/red',

    // When httpAdminRoot is used to move the UI to a different root path, the
    // following property can be used to identify a directory of static content
    // that should be served at http://localhost:1880/.
    //httpStatic: '/home/nol/node-red-static/',

    // The maximum size of HTTP request that will be accepted by the runtime api.
    // Default: 5mb
    //apiMaxLength: '5mb',

    // If you installed the optional node-red-dashboard you can set it's path
    // relative to httpRoot
    //ui: { path: "ui" },

    // Securing Node-RED
    // -----------------
    // To password protect the Node-RED editor and admin API, the following
    // property can be used. See http://nodered.org/docs/security.html for details.
    //adminAuth: {
    //    type: "credentials",
    //    users: [{
    //        username: "admin",
    //        password: "$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN.",
    //        permissions: "*"
    //    }]
    //},

    // To password protect the node-defined HTTP endpoints (httpNodeRoot), or
    // the static content (httpStatic), the following properties can be used.
    // The pass field is a bcrypt hash of the password.
    // See http://nodered.org/docs/security.html#generating-the-password-hash
    //httpNodeAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."},
    //httpStaticAuth: {user:"user",pass:"$2a$08$zZWtXTja0fB1pzD4sHCMyOCMYz2Z6dNbM6tl8sJogENOMcxWV9DN."},

    // The following property can be used to enable HTTPS
    // See http://nodejs.org/api/https.html#https_https_createserver_options_requestlistener
    // for details on its contents.
    // See the comment at the top of this file on how to load the `fs` module used by
    // this setting.
    //
    //https: {
    //    key: fs.readFileSync('privatekey.pem'),
    //    cert: fs.readFileSync('certificate.pem')
    //},

    // The following property can be used to cause insecure HTTP connections to
    // be redirected to HTTPS.
    //requireHttps: true

    // The following property can be used to disable the editor. The admin API
    // is not affected by this option. To disable both the editor and the admin
    // API, use either the httpRoot or httpAdminRoot properties
    //disableEditor: false,

    // The following property can be used to configure cross-origin resource sharing
    // in the HTTP nodes.
    // See https://github.com/troygoode/node-cors#configuration-options for
    // details on its contents. The following is a basic permissive set of options:
    //httpNodeCors: {
    //    origin: "*",
    //    methods: "GET,PUT,POST,DELETE"
    //},

    // If you need to set an http proxy please set an environment variable
    // called http_proxy (or HTTP_PROXY) outside of Node-RED in the operating system.
    // For example - http_proxy=http://myproxy.com:8080
    // (Setting it here will have no effect)
    // You may also specify no_proxy (or NO_PROXY) to supply a comma separated
    // list of domains to not proxy, eg - no_proxy=.acme.co,.acme.co.uk

    // The following property can be used to add a custom middleware function
    // in front of all http in nodes. This allows custom authentication to be
    // applied to all http in nodes, or any other sort of common request processing.
    //httpNodeMiddleware: function(req,res,next) {
    //    // Handle/reject the request, or pass it on to the http in node by calling next();
    //    // Optionally skip our rawBodyParser by setting this to true;
    //    //req.skipRawBodyParser = true;
    //    next();
    //},

    // The following property can be used to verify websocket connection attempts.
    // This allows, for example, the HTTP request headers to be checked to ensure
    // they include valid authentication information.
    //webSocketNodeVerifyClient: function(info) {
    //    // 'info' has three properties:
    //    //   - origin : the value in the Origin header
    //    //   - req : the HTTP request
    //    //   - secure : true if req.connection.authorized or req.connection.encrypted is set
    //    //
    //    // The function should return true if the connection should be accepted, false otherwise.
    //    //
    //    // Alternatively, if this function is defined to accept a second argument, callback,
    //    // it can be used to verify the client asynchronously.
    //    // The callback takes three arguments:
    //    //   - result : boolean, whether to accept the connection or not
    //    //   - code : if result is false, the HTTP error status to return
    //    //   - reason: if result is false, the HTTP reason string to return
    //},

    // Anything in this hash is globally available to all functions.
    // It is accessed as context.global.
    // eg:
    //    functionGlobalContext: { os:require('os') }
    // can be accessed in a function block as:
    //    context.global.os

    functionGlobalContext: {
        // os:require('os'),
        // octalbonescript:require('octalbonescript'),
        // jfive:require("johnny-five"),
        // j5board:require("johnny-five").Board({repl:false})
    },

    // The following property can be used to order the categories in the editor
    // palette. If a node's category is not in the list, the category will get
    // added to the end of the palette.
    // If not set, the following default order is used:
    //paletteCategories: ['subflows', 'input', 'output', 'function', 'social', 'mobile', 'storage', 'analysis', 'advanced'],

    // Configure the logging output
    logging: {
        // Only console logging is currently supported
        console: {
            // Level of logging to be recorded. Options are:
            // fatal - only those errors which make the application unusable should be recorded
            // error - record errors which are deemed fatal for a particular request + fatal errors
            // warn - record problems which are non fatal + errors + fatal errors
            // info - record information about the general running of the application + warn + error + fatal errors
            // debug - record information which is more verbose than info + info + warn + error + fatal errors
            // trace - record very detailed logging + debug + info + warn + error + fatal errors
            // off - turn off all logging (doesn't affect metrics or audit)
            level: "info",
            // Whether or not to include metric events in the log output
            metrics: false,
            // Whether or not to include audit events in the log output
            audit: false
        }
    }
}



I accessed the folder and checked the files on it
(
image attached)

And i rebbot the pc many times on the
process to fix it!

Thanks alot again!

Captura de tela de 2017-09-26 17-59-58.png

Colin Law

unread,
Sep 26, 2017, 5:18:56 PM9/26/17
to node...@googlegroups.com
Please read Nick's email again. As he said, you have to set httpStatic
to point to where the images are. Normally you would set this to
/home/user/.node-red/static and put the files there (that may even be
a default, not sure), but you have put the file in .node-red, not
node-red/static.

Colin

Diogo Zanardini

unread,
Sep 27, 2017, 3:49:54 PM9/27/17
to node...@googlegroups.com
hello

Im create the folder static in the folder :/home/user/.node-red
and put my img there...
and still broken...

lets try do this in other ways...

how would you do if you had to put a picture in your application from the beginning?

semething very simple like this:

[{"id":"caa3e568.085c3","type":"template","z":"997c34eb.1b76f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n<!DOCTYPE html>\n<html>\n<body>\n\n<img src=\"/smiley.gif\">\n\n</body>\n</html>\n","output":"str","x":307.5,"y":562,"wires":[["9f66cc14.a90168"]]}]


Where would you save the file?




[ ]´s
Diogo Zanardini

--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/m2eliEa3CFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send an email to node...@googlegroups.com.

Colin Law

unread,
Sep 27, 2017, 3:52:39 PM9/27/17
to node...@googlegroups.com
On 27 September 2017 at 20:49, Diogo Zanardini <diogoza...@gmail.com> wrote:
> hello
>
> Im create the folder static in the folder :/home/user/.node-red

And for that what have set httpStatic to?

> and put my img there...
> and still broken...
>
> lets try do this in other ways...
>
> how would you do if you had to put a picture in your application from the
> beginning?
>
> semething very simple like this:
>
> [{"id":"caa3e568.085c3","type":"template","z":"997c34eb.1b76f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"\n<!DOCTYPE
> html>\n<html>\n<body>\n\n<img
> src=\"/smiley.gif\">\n\n</body>\n</html>\n","output":"str","x":307.5,"y":562,"wires":[["9f66cc14.a90168"]]}]
>
>
> Where would you save the file?

In whatever folder you set httpStatic to.

Colin

Mark Setrem

unread,
Sep 27, 2017, 4:02:40 PM9/27/17
to Node-RED

You need to edit the settings.js file

change   the line

//httpStatic: '/home/nol/node-red-static/',

to be 
httpStatic: '/home/user/.node-red/static',

but change "user" to be the username that is running node-red

Diogo Zanardini

unread,
Sep 27, 2017, 4:40:10 PM9/27/17
to node...@googlegroups.com
Thanks Mark!!

I do that changes and reboot node-red even the pc and still not working...

what I do worng... =(

You need some log to chek out!?

thanks again for the patience...



[ ]´s
Diogo Zanardini

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/m2eliEa3CFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.

Diogo Zanardini

unread,
Sep 27, 2017, 4:48:06 PM9/27/17
to node...@googlegroups.com
Finaly was address typing error....
I put the right address and it worked!

Thanks again every one!

[ ]´s
Diogo Zanardini
Message has been deleted

Colin Law

unread,
Sep 27, 2017, 5:04:22 PM9/27/17
to node...@googlegroups.com
On 27 September 2017 at 21:47, Diogo Zanardini <diogoza...@gmail.com> wrote:
> Finaly was address typing error....
> I put the right address and it worked!

That is why you it is good to copy/paste when asking for help so
others can notice what you have done wrong.

Colin
>>> node-red+u...@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/bacaed28-c927-4dfb-93dd-a835735126d4%40googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>
> --
> 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+u...@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/CANhSv%3DtLoWcyuabNnj41Nx_f6R7oWgwF0a%3Dyy3VhZvzBu-Hj%2BA%40mail.gmail.com.

Diogo Zanardini

unread,
Sep 27, 2017, 5:04:30 PM9/27/17
to node...@googlegroups.com
Thanks Mark!

i think we heave a cross-information here!
The img is loaded as well
Every works fine, the last error is a simple whrong typing... I forgot the 's' on static


after I wrote it right, everything works incredibly right
😋

And thanks one more time for the help!

[ ]´s
Diogo Zanardini

2017-09-27 17:52 GMT-03:00 Mark Setrem <mse...@gmail.com>:
OK, 

1) What is the path to the settings.js file you have edited?

2) What user are you running using to run node-red?

3) Please paste the [info] lines that are printed when you start node-red

4) What is the full httpStatic: line you have edited in the settings.js fie?

5) What is the flow you are using to test this?  (please export and paste your flow) 


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/m2eliEa3CFA/unsubscribe.
To unsubscribe from this group and all its topics, 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.

Diogo Zanardini

unread,
Sep 27, 2017, 5:23:58 PM9/27/17
to node...@googlegroups.com
ok

[ ]´s
Diogo Zanardini


>>> 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/bacaed28-c927-4dfb-93dd-a835735126d4%40googlegroups.com.
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>
>>
>
> --
> 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

> 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
--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/m2eliEa3CFA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send an email to node...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages