Search code examples
node-red

Node-Red sends a message "require" is not defined


In the function node, customize the message sending mechanism, but require is not defined.

enter image description here


Solution

  • Details of how to load external modules for use in the Function Node are covered in the Node-RED Getting Started Guide here

    There are 2 options

    1. Adding the node to the functionGlobalContext by editing the settings.js file. e.g.

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

      Then load it in the function node with

      var os = global.get('osModule');
      
    2. Enabling functionExternalModules in settings.js, this will enable the ability to configure external modules in the function node editor. This feature is new in the 1.3.x release.