# Reading a file to use in a node's config dialog?

**URL:** <https://discourse.nodered.org/t/reading-a-file-to-use-in-a-nodes-config-dialog/80664>\
**Category:** Developing Nodes\
**Created:** [19 August 2023 17:54 UTC](https://discourse.nodered.org/t/reading-a-file-to-use-in-a-nodes-config-dialog/80664 "2023-08-19T17:54:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stwissel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stwissel/32/126_2.png) [@Stwissel](https://discourse.nodered.org/u/Stwissel)\
**Post date:** [19 August 2023 17:54 UTC](https://discourse.nodered.org/t/reading-a-file-to-use-in-a-nodes-config-dialog/80664/1 "2023-08-19T17:54:48Z")

</div>

I'm looking at upgrading the node-red-contrib-interactive-ssh node. I'd like to add the ability to allow picking a host configuration from the `~/.ssh/config` file. The config dialog runs in a browser, so obviously doesn't have access (and shouldn't) to the host's file system.  
How would I go about to provide a local function I could call to return some values read from a file on the host to use in the node's configuration file?

---

<div class="post-metadata">

**Author:** ![Stwissel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stwissel/32/126_2.png) [@Stwissel](https://discourse.nodered.org/u/Stwissel)\
**Post date:** [19 August 2023 18:39 UTC](https://discourse.nodered.org/t/reading-a-file-to-use-in-a-nodes-config-dialog/80664/2 "2023-08-19T18:39:09Z")

</div>

To answer my own question...  
I added to the JS file `interactive-ssh.js`

```js
RED.nodes.registerType('interactive-ssh', InteractiveSSH, {
    settings: {
      interactiveSshHosts: {
        value: extractHosts(),
        exportable: true
      }
    }
  });

```

with `extractHosts` a function on top of the file:

```js
onst fs = require('fs');
const SSHConfig = require('ssh-config');

const getStringFromFile = (source) => {
  const data = fs.readFileSync(source, {
    encoding: 'utf8',
    flag: 'r'
  });
  return data;
};

const extractHosts = () => {
  let fileName = process.env.HOME + '/.ssh/config';
  let cfgJson = getStringFromFile(fileName);
  let cfg = SSHConfig.parse(cfgJson);
  let result = [];
  for (let entry of cfg) {
    if (entry.param == 'Host') {
      result.push(entry.value);
    }
  }
  return result;
};

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 October 2023 18:39 UTC](https://discourse.nodered.org/t/reading-a-file-to-use-in-a-nodes-config-dialog/80664/3 "2023-10-18T18:39:30Z")

</div>

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