在节点红色函数中使用外部 js 库 [英] use an external js library in a node-red function
问题描述
我已经安装了一个 js 库 https://www.npmjs.com/package/fft 使用 npm,如何在节点红色函数中提供此功能?
I've installed a js library https://www.npmjs.com/package/fft with npm, how can I make this available in node-red functions ?
推荐答案
这已涵盖 Node-RED 文档的编写函数部分
您需要将 npm 模块添加到 settings.js
文件中.你可以在 ~/.node-red/
You need to add npm modules to the settings.js
file. You can find this file in ~/.node-red/
您要查找的部分是 functionGlobalContext
部分.
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);
...
还要注意安装 fft 模块的位置,它需要在 ~/.node-red/node_modules
中或全局安装,以便 Node-RED 可以访问它
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
这篇关于在节点红色函数中使用外部 js 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!