so i create new node
and need to sotre some data in context node
https://nodered.org/docs/creating-nodes/context
my node
module.exports = function(RED) {
function ClientNode(config) {
RED.nodes.createNode(this,config);
var node = this;
context.set("myData",1);
node.on('input', function(msg) {
msg.payload = this.context.get("myData");
// msg.payload = msg.payload.toLowerCase();
node.send(msg);
});
setTimeout(function () {
// this.context().flow.set("test", 1)
var msg = context.get("myData");
// msg.payload = msg.payload.toLowerCase();
node.send(msg);
}, 3000);
}
RED.nodes.registerType("Client",ClientNode);
RED.httpAdmin.post("/client/:id", RED.auth.needsPermission("client.write"), function(req,res) {
var node = RED.nodes.getNode(req.params.id);
if (node != null) {
try {
msg = {payload:"", topic:""}
msg.payload = node.name;
msg.topic = node.id
msg.z = node.z
node.send(msg);
res.sendStatus(200);
} catch(err) {
res.sendStatus(500);
node.error("Restore failed: "+ err.toString());
}
} else {
res.sendStatus(404);
}
});
}
but I cant
am try with :
this.context().set("data", 1);
this.context.set("data", 1);
context().set("data", 1);
context.set("data", 1);
but all not work
error in console log
10 Nov 08:54:34 - [error] [Client:728bd51e7616989f] ReferenceError: context is not defined
or
10 Nov 08:53:16 - [error] [Client:728bd51e7616989f] TypeError: this.context.set is not a function