存储 API 提供了一种可插拔的方式来配置 Node-RED 运行时存储数据的位置。
API 存储的信息包括
默认情况下,Node-RED 使用此 API 的本地文件系统实现。
API 函数文档请参见此处。
settings.js 中的 storageModule
属性可用于指定要使用的自定义模块
storageModule: require("my-node-red-storage-plugin")
此 API 广泛使用 JavaScript Promise。
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
});
版权所有 OpenJS 基金会和 Node-RED 贡献者。保留所有权利。OpenJS 基金会已注册商标并使用商标。有关 OpenJS 基金会商标列表,请参阅我们的商标政策和商标列表。未在OpenJS 基金会商标列表中指明的商标和徽标是其各自所有者的商标™ 或注册® 商标。使用它们并不意味着与它们有任何关联或得到它们的认可。
OpenJS 基金会 | 使用条款 | 隐私政策 | OpenJS 基金会章程 | 商标政策 | 商标列表 | Cookie 政策