Like this @wilson2517 ...
var entrada = msg.payload;
var testset = context.get("testset"); // Retrieve the stored timeout reference
if (entrada == "on") {
testset = setTimeout(function() {
msg.payload = "active";
node.send(msg);
}, 2000);
context.set("testset", testset); // Store the timeout reference for future use
}
if (entrada == "off") {
clearTimeout(testset); // Clear the timeout
context.set("testset", null); // Clear the stored timeout reference
}