Skip to content Skip to sidebar Skip to footer

'require' Keyword Doesn't Work Within Node Red Function Node

first line in a Node red Function Node is var moment = require('moment-timezone'); ... I am trying to establish a timezone correct date/time stamp for sensor data. I get the follow

Solution 1:

As this GitHub issue answer states, you cannot use require itself inside a function node, but you can add external modules to the sandbox used to run functions. You would do this setting functionGlobalContext inside your settings.js file like the following:

functionGlobalContext: {
    tzModule:require('moment-timezone')
}

The module can then be referenced by using the following code:

var moment = global.get('tzModule');

Check out the Node-RED documentation on global-context for full details.


Solution 2:

Settings file:/Users/aiquantong/.node-red/settings

Please do configure in this file, it will be working.


Post a Comment for "'require' Keyword Doesn't Work Within Node Red Function Node"