
Product
Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
@allanoricil/nrg-nodes
Advanced tools
A very simple lib that aims to ease and structure the creation of custom node-red nodes using ES6+ featues
A very simple lib that aims to ease the creation of node-red nodes using ES6+ features.
[!IMPORTANT] This lib does not provide or use typescript types for node-red objects or methods
import { Node } from "@allanoricil/nrg-nodes";
import fetch from "node-fetch";
export default class MyCustomNodeClass extends Node {
constructor(config) {
super(config);
this.log(`constructed type: ${this.type} id: ${this.id}`);
}
// NOTE: Unlike the constructor, this executes only once, regardless of how many nodes of this type are in the flow.
static init() {
Node.RED.httpAdmin.get("/test", async function (req, res) {
try {
res.status(200).json({ message: "success" });
} catch (err) {
Node.RED.log.error("ERROR:" + err.message);
res.status(500).json({ message: "something unknown happened" });
}
});
}
// NOTE: Implement this method if your node has credentials. This object is passed to `RED.nodes.registerType("type", MyCustomNodeClass, { credentials })`
static credentials() {
return {
username: { type: "text", required: true },
password: { type: "password", required: true },
};
}
/*
NOTE: Considering this node's implementation is located at ./src/nodes/node-1/server/index.js, its type will be node-1.
Therefore, the "customSetting" shown below will be accessible as 'RED.settings.node1CustomSetting' in both client and server side.
Read this doc to understand more: https://nodered.org/docs/creating-nodes/node-js#custom-node-settings
It feels weird, but this is how Node-RED is currently handling custom settings. I hope that in the future settings are scoped by node's type using another nested property. For example `RED.settings.["node-1"].customSettings`
*/
static settings() {
return {
customSetting: {
value: "default",
exportable: true,
},
};
}
async onInput(msg, send, done) {
try {
this.log("node-1 on input", msg.payload);
this.status({
fill: "blue",
shape: "ring",
text: "fetching data",
});
const response = await fetch("https://dog.ceo/api/breeds/image/random");
this.status({
fill: "green",
shape: "dot",
text: "success",
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
msg.payload = data;
send(msg);
done();
} catch (error) {
this.status({
fill: "red",
shape: "ring",
text: "error",
});
this.error("Failed to fetch dog image:", error);
done(error);
} finally {
setTimeout(() => {
this.status({});
}, 3000);
}
}
onClose(removed, done) {
if (removed) {
this.log(`type: ${this.type} id: ${this.id} disabled/deleted`);
} else {
this.log(`type: ${this.type} id: ${this.id} restarted`);
}
done();
}
}
FAQs
A very simple lib that aims to ease and structure the creation of custom node-red nodes using ES6+ featues
We found that @allanoricil/nrg-nodes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.
Research
A malicious package uses a QR code as steganography in an innovative technique.