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

后端 未结 2 422
清歌不尽
清歌不尽 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.

提交回复
热议问题