Node-RED UUID Generator
node-red-contrib-uuid is a Node-RED node designed for the simple and fast generation of RFC4122 compliant Universally Unique Identifiers (UUIDs) within Node-RED flows. It leverages the robust `uuid` npm package internally to ensure standard-compliant and cryptographically strong UUIDs. As of version 0.0.4-rc-1, it is in a release candidate stage, indicating active development and refinement. Node-RED contrib nodes typically follow an independent release cadence, often tied to feature enhancements or updates in their underlying dependencies like the `uuid` library. Its primary differentiator is providing a drag-and-drop solution for UUID generation directly within the Node-RED visual programming environment, abstracting the complexities of the underlying `uuid` library for flow developers.
Common errors
-
Error: Cannot find module 'node-red-contrib-uuid'
cause The package was not installed correctly in the Node-RED user directory or Node-RED was not restarted after installation.fixNavigate to your Node-RED user directory (usually `~/.node-red`) and run `npm install node-red-contrib-uuid`. Then restart your Node-RED instance (e.g., `node-red-restart` or `pm2 restart node-red`). -
npm WARN deprecated uuid@X.Y.Z: Please upgrade to version 7 or higher.
cause The `node-red-contrib-uuid` package, or another dependency, is using an outdated and potentially insecure version of the `uuid` library.fixWhile `node-red-contrib-uuid` maintains its own dependencies, this warning suggests its internal `uuid` version might be old. Monitor for updates to `node-red-contrib-uuid`. If the warning persists and you're using `uuid` directly in a Function node, update your `uuid` dependency to `@latest` (version 7 or higher) in your Node-RED `package.json` and ensure it's accessible. -
ReferenceError: uuidv4 is not defined
cause Attempting to use `uuid` in a Node-RED Function node without properly declaring it as an external module.fixIn the Function node's 'Setup' tab, add 'uuid' as a module (e.g., 'uuidv4' for the variable name, 'uuid' for the module name). Then in your function code, you can use `const { v4: uuidv4 } = global.get('uuidv4')` or simply `const uuidv4 = require('uuid').v4;` if configured via `settings.js`.
Warnings
- breaking The underlying `uuid` library has undergone significant breaking changes across major versions (v7, v8, v9, v10, v11, v14). These include dropping Node.js 10.x, 12.x, 14.x, 18.x support, removing the default export, deprecating deep imports (e.g., `uuid/v4`), and transitioning to ESM-only in recent versions. While `node-red-contrib-uuid` abstracts this, maintainers must ensure the internal `uuid` dependency version is compatible with Node-RED's runtime Node.js version and handle `uuid`'s breaking changes.
- deprecated Older versions of the `uuid` library (specifically `uuid@3.x`) were deprecated due to their reliance on `Math.random()` for certain UUID versions, which is known to be cryptographically insecure. Using such versions can lead to predictable or duplicate UUIDs in sensitive applications.
- gotcha Node-RED contrib nodes, including `node-red-contrib-uuid`, might not immediately appear in the palette after installation if Node-RED isn't restarted or if there are package installation issues. Errors during Node-RED startup or palette loading can also prevent nodes from showing up.
Install
-
npm install node-red-contrib-uuid -
yarn add node-red-contrib-uuid -
pnpm add node-red-contrib-uuid
Imports
- v4
import uuidv4 from 'uuid/v4'; // Deprecated since uuid@7, removed default export import uuid from 'uuid'; console.log(uuid.v4()); // Default export removed in uuid@8+
import { v4 as uuidv4 } from 'uuid'; - v1
const uuidv1 = require('uuid/v1'); // Deprecated deep import, use named exportsimport { v1 as uuidv1 } from 'uuid'; - randomUUID
import { v4 } from 'uuid'; // While v4 is good, node:crypto.randomUUID is often faster in Node.js >=14.17.0/15.6.0.import { randomUUID } from 'node:crypto';
Quickstart
[{"id":"435a2d67.123456","type":"inject","z":"a1b2c3d4.567890","name":"Trigger UUID","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":100,"wires":[["e8f9g0h1.234567"]]},{"id":"e8f9g0h1.234567","type":"uuid","z":"a1b2c3d4.567890","name":"Generate UUID","version":"v4","outputProperty":"payload","x":340,"y":100,"wires":[["210fe3dc.987654"]]},{"id":"210fe3dc.987654","type":"debug","z":"a1b2c3d4.567890","name":"Show UUID","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":100,"wires":[]}]