存储API提供了一种可插拔的方式来配置Node-RED运行时存储数据的位置。
API存储的信息包括:
默认情况下,Node-RED使用该API的本地文件系统实现。
API函数文档请参阅此处。
settings.js 中的 storageModule
属性可用于指定要使用的自定义模块:
storageModule: require("my-node-red-storage-plugin")
该API广泛使用了JavaScript promises。
Promise(承诺)代表异步操作的最终结果。在结果可用之前,它充当占位符。
Node-RED使用When.js库。以下示例展示了它的使用方式。如需更完整的示例,默认文件系统实现位于red/runtime/storage/localfilesystem.js
。
function getFlows() {
// create and return a promise
return when.promise(function(resolve,reject) {
// resolve - a function to be called with the successful result
// reject - a function to be called if an error occurs
// do some asynchronous work, with a callback on completion
doAsyncWork(function(err,result) {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
}
getFlows()
.then(function(result) {
// Called when getFlows completes successfully
})
.otherwise(function(err) {
// Called when getFlows hits an error
});
Node-RED: 面向事件驱动应用的低代码编程平台。
版权所有 OpenJS基金会 及 Node-RED 贡献者。保留所有权利。OpenJS基金会 拥有注册商标并使用商标。有关 OpenJS基金会 的商标列表,请参阅我们的 商标政策 和 商标列表。未在 OpenJS基金会商标列表 中标注的商标™或注册®商标归其各自持有人所有。使用这些商标并不意味着与它们有任何关联或获得其认可。
The OpenJS Foundation | 使用条款 | 隐私政策 | OpenJS基金会章程 | 商标政策 | 商标列表 | Cookie政策