0

As this question and NodeRed suggests, I need to include this in settings.js in order to use a module inside a function node:

 functionGlobalContext: {
     osModule:require('os')
},

Followed by

var osMod = global.get('osModule');

msg.payload = osMod.platform();

return msg;

In the function node as a simple example, which returns the "TypeError: Cannot read property 'platform' of undefined" error.

What am I doing wrong?

user2993349
  • 491
  • 1
  • 5
  • 16
  • Is your `settings.js` being loaded? – Jared Smith Aug 07 '17 at 13:19
  • I altered the default settings file that came with NodeRed, but didn't have to mess with it until now. Since I'm not specifing another file, it should use this one, according to: https://nodered.org/docs/configuration. – user2993349 Aug 07 '17 at 13:52
  • I ask because you appear to have read the documentation correctly but the `global.get('osModule')` is clearly returning `undefined` meaning that the sandbox is not being properly pre-populated with that module. I'd try specifying that particular settings file with a CLI argument. – Jared Smith Aug 07 '17 at 14:01
  • Which settings.js did you edit? Are you 100% sure you are using the one in the userDir? Node-RED logs which settings file it's using at startup – hardillb Aug 07 '17 at 14:06
  • Yup, it was actually getting a completely unrelated settings file in another folder instead of the installation folder. It was saving the settings and flows somewhere else. How do I change where the .node-red directory is created? – user2993349 Aug 07 '17 at 14:57

0 Answers0