Using SHA or MD5 inside function-node

Is it possible to use the already existing crypto-js of Node-Red to use it inside the Function-node?
Inside a for-loop I want to check if a part of a package is altered compared to my context-database. If so, I want to update that part. Because it happens inside a for-loop and only checks parts of an array, I want to use it inside my function-node and not outside with an external node.

If you are using newer version of node-red, you can import the crypto library on the function node setup tab...



Demo Flow...

[{"id":"d3ad5e25c27b5344","type":"inject","z":"c6ecb8c5c651ca06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"we love node-red","payloadType":"str","x":260,"y":140,"wires":[["4b9f5f72b1099bc1"]]},{"id":"4b9f5f72b1099bc1","type":"function","z":"c6ecb8c5c651ca06","name":"sha256","func":"msg.payload = crypto\n    .createHash(\"sha256\")\n    .update(msg.payload)\n    .digest(\"hex\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"crypto","module":"crypto"}],"x":480,"y":140,"wires":[["bb173a2ab61486d3"]]},{"id":"ee9dd58b761ca1fb","type":"inject","z":"c6ecb8c5c651ca06","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Drink more coffee","payloadType":"str","x":260,"y":180,"wires":[["4b9f5f72b1099bc1"]]},{"id":"bb173a2ab61486d3","type":"debug","z":"c6ecb8c5c651ca06","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":700,"y":140,"wires":[]}]

I have updated it, but I can't get the node version to update as well. I run Node-Red on a raspberry pi and use the script from the website to update Node-Red. But with --node14 I still get version 12.

did you run the command correctly? ...

bash <(curl -sL --node14

Do you have n or nvm installed? These are often a cause of installation issues.

Not that I know of.
Version Node.js: v12.22.7
Version Npm: 6.14.15

what do you get if you enter the following in the terminal...
which n
which nvm

Also, try running this script once more (as I wrote it above) and capture the output and log file - paste into reply as text (press the code </> button then paste log/output between the backticks)

For which n and which nvm I got nothing.
No response just this:
pi@raspberrypi:~ $ which n
pi@raspberrypi:~ $ which nvm
pi@raspberrypi:~ $

I tried to add the log by pressing </> but the size exceeded the limit.
The log:
install log.log (74.3 KB)

Ok, good.

I think your system needs updating. Can you do sudo apt-get update then sudo apt-get upgrade

Then remove node sudo apt-get purge nodejs

After that, run sudo apt autoremove then sudo apt autoclean to clean up any install files

Then try the script again as I posted above.

Please include a copy of the terminal this time.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.