HTTPS setting. `fs` module - huh?

Sorry to drag this up (again?):

Looking in the settings.js file there are these lines:

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

Interesting. With this setting active, it forces https connections. Which is good for security.
Not too important for me just now, but I like to keep my options open and learn. (Well: try to...)

So as I see it:

// Uncomment the following to make it available:

Which is self explanatory but for the preseeding (?) statement:

// The `https` setting requires the `fs` module.

Searching >>fs module node-red<< gets me results on the filesystem node more than the fs module.

(See attached)

How do I get more information on this "required fs module"?

If you look further down in the settings.js file you'll find the commented out https setting. It looks like this:

//https: {
//    key: fs.readFileSync('privatekey.pem'),
//    cert: fs.readFileSync('certificate.pem')
//},

This is because the https setting requires you to provide two properties - key and cert and have them set to the appropriate certificate files needed for https. In order to load the content of those files, the commented out example uses the fs.readFileSync function to load the contents of those files.

But to do that, you need to have required the fs module - hence the comment at the top of the file.

The fs module is a built-in module of node.js. It is documented here: https://nodejs.org/api/fs.html

You don't need to install the 'fs' module @Trying_to_learn, just uncomment it in the NR settings, and node-RED will sort it out for you.

Thanks Paul and Nick.

I only asked because - to me - it was a bit confusing.

Nick,
The original part I posted and the part you posted as "further down"....

That is a long way down.
As the first part is "outside" the

module.exports = {

Part, and the part you mentioned was about .... 80 (?exact value? lines below the connection was lost to me.

If the lines:

and

Are related: why are they so far apart?

May I suggest the first part is put closer to the second, unless there is a reason that it is outside the

module.exports = {

scope.

If it is, could the second part be put a bit closer to the top so the association remains valid?

I am only asking/discussing this. It isn't important at this time for me. I am reading things and trying to take it in.

The require statement cannot be inside the module.exports = { ... } object.

The comment talks about the https setting. It doesn't take much to search the file for https and find the https setting. I see limited value in moving it further up.

1 Like

Ok.

Fair enough.

I suspected what you said to be true about:

But wanted to be sure.