'require' keyword doesn't work within Node Red Function node

后端 未结 2 429
清歌不尽
清歌不尽 2021-02-10 02:34

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

相关标签:
2条回答
  • 2021-02-10 03:21

    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.

    0 讨论(0)
  • 2021-02-10 03:25
    Settings file:/Users/aiquantong/.node-red/settings

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

    0 讨论(0)
提交回复
热议问题