use an external js library in a node-red function

大兔子大兔子 提交于 2019-12-23 12:57:47

问题


I've installed a js library https://www.npmjs.com/package/fft with npm, how can I make this available in node-red functions ?


回答1:


This is covered Writing Functions sections of the Node-RED docs

You need to add npm modules to the settings.js file. You can find this file in ~/.node-red/

The section you are looking for is the functionGlobalContext section.

...
functionGlobalContext: {
   fft: require('fft')
},
...

You would then access the module in the function node with the following:

var FFT = context.global.get('fft');
var fft = new FFT(n, inverse);
...

Also be careful where you installed the fft module, it needs to be either in ~/.node-red/node_modules or installed globally so it is accessable to Node-RED



来源:https://stackoverflow.com/questions/38481130/use-an-external-js-library-in-a-node-red-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!