UNPKG

node-red-contrib-key-value-store

Version:
25 lines (20 loc) 515 B
'use strict'; module.exports = RED => { function KeyValueReadNode(n) { RED.nodes.createNode(this, n); this.store = RED.nodes.getNode(n.store); this.key = n.key; this.on('input', msg => { const key = this.key || msg.topic; return this.store.get(key) .then(data => { msg.payload = data; this.send(msg); }) .catch(err => { this.error(err); }); }); }; RED.nodes.registerType('key-value-read', KeyValueReadNode); };