How to get the device name "hostname"

Hello I need to get the name of my device "hostname" (is a raspberry) where is loaded Node-red.
So I need to create a payload with the name of the device (set by Pi configuration form -> "hostname" field)

Thank you

an exec node set to run hostname ?
(and don't append the payload from the incoming message.)

1 Like

By "hostname", do you mean "myDeviceName"?

That is in the settings.js file.

1 Like

Add 'os:requrie('os') item to the global context... example of this is in the settings file how to do this.

Then you just do a global get to the 'os' node to get the hostname() function results. For example I do this at times in a function node...

var theHost = global.get('os').hostname().split('.')[0];

The above gets just 'host' name, ignoring any domain name element of the host FQDN (Full Qualified Doman Name) returned. So 'host' not '' for example.

1 Like

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