create account

Create a Random Word Generator with Node-Red by wwwiebe

View this thread on: hive.blogpeakd.comecency.com
· @wwwiebe ·
$10.22
Create a Random Word Generator with Node-Red
A few weeks ago I posted about using low-code/no-code software to build a "word of the day blog post" generator. My initial idea was to build one use the free version of the software from the company I work for, and I did! It worked. Until marketing got overzealous with a software update and wiped out my work. 

Alas.

So I've decided to redo, but this time I will use a self-hosted Node-Red instance.


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23xKxqicp3ZFkYMXwiiSjTKzFMDkJ2nXjhqsm3uRUq9iCAnPAGomiheNFMMoxeyVhBwsx.png)

I need to say, I really, really, really like Node-Red. Every single time I use it I feel good and warm on the inside. Node-Red is an open source project with open source addons for it and, every time I look for something new, it's their, and I end up feeling that there isn't anything Node-Red would not be able to do.

For those unfamiliar, Node-Red is a "low-code/no-code," or "drag and drop" utility, used originally to built Internet of Things automations. It has since grown in popularity and can now do so much more.

To show the drag and drop capabilities of Node-Red, let's build the most simple type of flow: the current timestamp.

* On a Node-Red instance simply click the "Inject" node onto the canvas.

![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/Eo2BNseDscGAecQtNHRzTm55QSCZ1yigt5QqNKxKMeUcg1cxqwtq9dLwR6Q4KwZh3ud.png)
 
* Drag the "Debug" node onto the canvas. I like to put my side by side, but the canvas is flexible.

![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23tcNzkBCx63R4BYETPH42MdjKQ5ybmTs8Ts8E2J14y76qkUPmkdYegxZUinbmBLfM5zD.png)

* Click on the small grey button on the right of the timestamp node (this is the *output* of the timestamp node) and drag it to the small grey button on the left of the debug node (this is the *input* of the debug node)

![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23u6YdYs1GCCQ12ybdy2ohMo1WeSnUPxaTNZub8KZ18qdLL3qzgokpuiQpNf8Ytic2crc.png)


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23xVkanYc6hiNRqhX6NvmabEqGCo9Ypg7Ng5ZwL1spaTmWvuvgyK6DjqTbtFkSfQeB9uA.png)

This creates a flow link between the two nodes: The timestamp node sends it's output to the debug node. The debug node can then do whatever it wants with it.

Then do the following three tasks in order:

1. Deploy the flow.
2. View the debug page.
3. Run the flow by pressing the timestamp button.

Expected result: In the debug pane you will see a timestamp of a number of digits. That value is the number of *microseconds* that have elapsed since January 1, 1970. We call this epoch time. Don't worry about that we won't use it for the remainder of the tutorial. The purpose of this example is to show just how easy using Node-Red can be.

![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23t8D1dSffWEpAzNcVsk8oDiHFfzoqpHSNa9abhWgayP2ppFhjWNnySJvw3f8iFNsrAPD.png)

**Using the Internet**

So what we want to do is use Node-Red to perform two functions:

1. Get a random word.
2. Get the definition for that word.

There are publicly available resources to do this.

*Random Word*

A random word can be obtained by browsing to https://random-word-api.herokuapp.com/word. Go ahead. Open a browser and try it. You'll see a word. It will be in square brackets.

The square brackets indicate that what is inside them is a *list*. In this case it is a list of one item, but there could be more. 

Let's do something with this in Node-Red.  Node-Red has a series of nodes or network utilities. This is exactly what we want! In fact, we want the *http request* node, since all we need to do is use that one URL (as a web/http request) to get a word. 

![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23t8CoYXHpNdwb1JRiwXF5nYQTEp6NjNovFY23155KTHsGaWhpHt2g1rzBnA6LE8ceLGC.png)

Simply dragging the http request node onto the connecting line between the timestamp and debug nodes puts it into the flow.


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23x1atZJxsV92hSHqKW1VUT4aqYmoHjMNcfs8gu7C4byyFDFj76PSvc4KLcg8nMfXzuJ2.png)

Now, double click on the http request node to open up the toolbox. There will be a field to input the URL we want to query. Ultimately it will look like this:


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23w38LU8cg3xWy2Az1F5VXwryE5QJcyeYT3u7MdAp1ScHLoDPPNZB6qCWfn9QVVbm1mP6.png)

Hit *Done* on the toolbox. Since we have modified the flow we need to deploy it again, so press the Deploy button top right, then press on the timestamp node again. See that we have successfully pulled a word! Woot!


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/23t8CsxKJAvZx6vncqZfGu8r2cp8TPvf5Gvm4FCrtFNYgcqKarWCcak4m2jJA6KHaBR78.png)

Now we want to do something with that and, at this point, some knowledge of programming/coding/scripting is required. This is where the technical portion of the post begins.

Node-Red passes messages from node to node by the use of an object named "msg". The *msg* object contains a host of information, but the one we are really interested in is *msg.payload*. The payload object, in this case a list, contains the word. Because we know that the list contains only one item we can easily reference it as *msg.payload[0]*.

*Word Definition*

https://dictionaryapi.dev/ can be used to get the definition of a word using this syntax:

`https://api.dictionaryapi.dev/api/v2/entries/en/<word>`

To do this I will simply take the initial word from the first http request node, use a function with some javascript to build the url accordingly, such as this:

`https://api.dictionaryapi.dev/api/v2/entries/en/stubble`


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/Eo8ZYbAa1Rj2uKvbRZfFWF2CiGc8yL3Jv1MfS7pFpubbp1QBEnNr3JtVpkM8dDJrK5F.png)

and then use a second http request node to query dictionaryapi.dev. The result, as seen in our new debug, is a full definition of the word.

**Next Steps**

This flow works, but it's barebones and I do not like the names of the nodes. Each node/block can be renamed by double clicking on it, so to make it easier to read and understand I've done just that:


![image.png](https://files.peakd.com/file/peakd-hive/wwwiebe/EoKCaRW1MifvzDjiNcdo7N16onCoui1CzPVFZJazETQbfwa6QerhjtzBhBsENZd7jLK.png)

Beyond that there are ways to make this work better:

1. Use a conditional in case "get random word" does not return a word and exit cleanly.
2. Use a conditional in case "get definition" does not return a definition and exit cleanly.
3. Clean up the final msg.payload with the definition to format it to be easier to read.

My initial idea was to then use the chatai api to have an AI generated paragraph showing how the word can be used. This is doable in Node Red! That will be the subject of a later post.

---

(c) All images and photographs, unless otherwise specified, are created and owned by me.
(c) Victor Wiebe

---

**About Me**

```
Sometimes photographer. Wannabe author. Game designer. Nerd. 
General all around problem-solver and creative type.
```

---

**Blind Skeleton**

[![Blind Skeleton Banner.png](https://files.peakd.com/file/peakd-hive/wwwiebe/EnyoWjSiaCvtkQU3fLnf9mPMurmZf5Yc3fwX2auVyEk7xMSnyYq9BfZrXVeCoonTwzF.png)](https://blindskeleton.one/)

Online Radio: https://blindskeleton.one/radio/
Three Tune Tuesday Live Stream: 12:00pm (noon) EST

**Frogs of War Games**

[![Frogs of War Banner.png](https://files.peakd.com/file/peakd-hive/wwwiebe/EnymfvBXvMjKoEiVr8fyCfr4vGqWsvyGYeSJeYtvqHpdMRg7By72MGbc7TC6iKmZnhD.png)](https://frogsofwargames.com/)

**Tidwick**

[![Tidwick Banner.png](https://files.peakd.com/file/peakd-hive/wwwiebe/Eo4C7Mv8kgBKfwhcc8jWcv1kDxu3gXkz7yEHAvS8zikefjNX5GWKfRNZpRz82guy7VM.png)](https://tidwick.com/)

**The Feet Community**

[![Feet Banner.png](https://files.peakd.com/file/peakd-hive/wwwiebe/EnywDrFFwZ2xGHMnyi6hvNbd8KVz1AX4CUm16CvEHieH6C2cVpNP8ButgxkUPFQmQ5r.png)](https://peakd.com/c/hive-128095/)

**What I Learned Today**

[![What I Learned Today Banner.png](https://files.peakd.com/file/peakd-hive/wwwiebe/EnyvMPaTM76UDZrFDHG6h8TP3vPLaTvrUV1dD6ZHiXSp654kjTorrTXJ6ENbzweydPW.png)](https://peakd.com/c/hive-131257/)



👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 461 others
properties (23)
authorwwwiebe
permlinkcreate-a-random-word-generator-with-node-red
categoryhive-196387
json_metadata{"app":"peakd/2023.1.1","format":"markdown","tags":["pimp","proofofbrain","neoxian","palnet","cent","archon","vyb","creativecoin","waivio","slothbuzz"],"users":[],"image":["https://files.peakd.com/file/peakd-hive/wwwiebe/23xKxqicp3ZFkYMXwiiSjTKzFMDkJ2nXjhqsm3uRUq9iCAnPAGomiheNFMMoxeyVhBwsx.png","https://files.peakd.com/file/peakd-hive/wwwiebe/Eo2BNseDscGAecQtNHRzTm55QSCZ1yigt5QqNKxKMeUcg1cxqwtq9dLwR6Q4KwZh3ud.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23tcNzkBCx63R4BYETPH42MdjKQ5ybmTs8Ts8E2J14y76qkUPmkdYegxZUinbmBLfM5zD.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23u6YdYs1GCCQ12ybdy2ohMo1WeSnUPxaTNZub8KZ18qdLL3qzgokpuiQpNf8Ytic2crc.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23xVkanYc6hiNRqhX6NvmabEqGCo9Ypg7Ng5ZwL1spaTmWvuvgyK6DjqTbtFkSfQeB9uA.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23t8D1dSffWEpAzNcVsk8oDiHFfzoqpHSNa9abhWgayP2ppFhjWNnySJvw3f8iFNsrAPD.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23t8CoYXHpNdwb1JRiwXF5nYQTEp6NjNovFY23155KTHsGaWhpHt2g1rzBnA6LE8ceLGC.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23x1atZJxsV92hSHqKW1VUT4aqYmoHjMNcfs8gu7C4byyFDFj76PSvc4KLcg8nMfXzuJ2.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23w38LU8cg3xWy2Az1F5VXwryE5QJcyeYT3u7MdAp1ScHLoDPPNZB6qCWfn9QVVbm1mP6.png","https://files.peakd.com/file/peakd-hive/wwwiebe/23t8CsxKJAvZx6vncqZfGu8r2cp8TPvf5Gvm4FCrtFNYgcqKarWCcak4m2jJA6KHaBR78.png","https://files.peakd.com/file/peakd-hive/wwwiebe/Eo8ZYbAa1Rj2uKvbRZfFWF2CiGc8yL3Jv1MfS7pFpubbp1QBEnNr3JtVpkM8dDJrK5F.png","https://files.peakd.com/file/peakd-hive/wwwiebe/EoKCaRW1MifvzDjiNcdo7N16onCoui1CzPVFZJazETQbfwa6QerhjtzBhBsENZd7jLK.png","https://files.peakd.com/file/peakd-hive/wwwiebe/EnyoWjSiaCvtkQU3fLnf9mPMurmZf5Yc3fwX2auVyEk7xMSnyYq9BfZrXVeCoonTwzF.png","https://files.peakd.com/file/peakd-hive/wwwiebe/EnymfvBXvMjKoEiVr8fyCfr4vGqWsvyGYeSJeYtvqHpdMRg7By72MGbc7TC6iKmZnhD.png","https://files.peakd.com/file/peakd-hive/wwwiebe/Eo4C7Mv8kgBKfwhcc8jWcv1kDxu3gXkz7yEHAvS8zikefjNX5GWKfRNZpRz82guy7VM.png"]}
created2023-01-27 19:13:24
last_update2023-01-27 19:13:24
depth0
children7
last_payout2023-02-03 19:13:24
cashout_time1969-12-31 23:59:59
total_payout_value5.160 HBD
curator_payout_value5.055 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length8,162
author_reputation318,663,954,734,459
root_title"Create a Random Word Generator with Node-Red"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,246,940
net_rshares19,024,437,127,933
author_curate_reward""
vote details (525)
@alexanderalexis · (edited)
$0.03
Can be useful for training your vocabulary I guess. Is that its use-case?
Edit: Oh I see, it's like a Merriam-Webster 'word of the day' kinda thing.
👍  
properties (23)
authoralexanderalexis
permlinkrp7m6s
categoryhive-196387
json_metadata{"app":"hiveblog/0.1"}
created2023-01-28 19:01:42
last_update2023-01-28 19:02:51
depth1
children2
last_payout2023-02-04 19:01:42
cashout_time1969-12-31 23:59:59
total_payout_value0.012 HBD
curator_payout_value0.013 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length148
author_reputation1,916,610,782,909
root_title"Create a Random Word Generator with Node-Red"
beneficiaries
0.
accounthiveonboard
weight100
1.
accountroomservice
weight100
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,272,276
net_rshares48,642,005,162
author_curate_reward""
vote details (1)
@wwwiebe ·
Actually, the original use case was just to use multiple different "endpoints" to automate building a blog post because, ultimately, I'm pretty lazy. I'm scrapping the idea of writing posts with it, but the concept of automation can be used for so many other purposes.

I actually receive the Merriam-Webster word of the day on a .. well .. on a daily basis. It's pretty fun.
👍  ,
properties (23)
authorwwwiebe
permlinkre-alexanderalexis-rp88be
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2023.1.1"}
created2023-01-29 02:59:42
last_update2023-01-29 02:59:42
depth2
children1
last_payout2023-02-05 02:59:42
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length375
author_reputation318,663,954,734,459
root_title"Create a Random Word Generator with Node-Red"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,282,325
net_rshares18,782,569,477
author_curate_reward""
vote details (2)
@alexanderalexis ·
$0.03
Laziness is a great motive. Much work has been done by lazy people trying to make life less work for themselves :D
👍  
properties (23)
authoralexanderalexis
permlinkrp9cx4
categoryhive-196387
json_metadata{"app":"hiveblog/0.1"}
created2023-01-29 17:36:39
last_update2023-01-29 17:36:39
depth3
children0
last_payout2023-02-05 17:36:39
cashout_time1969-12-31 23:59:59
total_payout_value0.015 HBD
curator_payout_value0.015 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length114
author_reputation1,916,610,782,909
root_title"Create a Random Word Generator with Node-Red"
beneficiaries
0.
accounthiveonboard
weight100
1.
accountroomservice
weight100
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,297,137
net_rshares55,498,872,837
author_curate_reward""
vote details (1)
@hannes-stoffel ·
Thanks a lot for sharing this, Node-Red looks very interesting. 
I wonder if there's a way to make calls the a hive node? I.e. write a program that can do things on the chain like the tipping bots.

properties (22)
authorhannes-stoffel
permlinkre-wwwiebe-rp5vh3
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2023.1.1"}
created2023-01-27 20:27:09
last_update2023-01-27 20:27:09
depth1
children1
last_payout2023-02-03 20:27:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length199
author_reputation38,938,157,671,746
root_title"Create a Random Word Generator with Node-Red"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,248,737
net_rshares0
@wwwiebe ·
It certainly would be well suited to it! I've used it to create a Discord bot that listens 24x7, so having something that listens to the blockchain 24x7 is certainly possible. The current caveat is that the Hive libraries haven't been imported as new Node Red modules, which is a task quite beyond me. I would sure make use of it, though, if it were to happen!
properties (22)
authorwwwiebe
permlinkre-hannes-stoffel-rp87ye
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2023.1.1"}
created2023-01-29 02:51:54
last_update2023-01-29 02:51:54
depth2
children0
last_payout2023-02-05 02:51:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length360
author_reputation318,663,954,734,459
root_title"Create a Random Word Generator with Node-Red"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,282,198
net_rshares0
@stemsocial ·
re-wwwiebe-create-a-random-word-generator-with-node-red-20230128t042938135z
<div class='text-justify'> <div class='pull-left'>
 <img src='https://stem.openhive.network/images/stemsocialsupport7.png'> </div>

Thanks for your contribution to the <a href='/trending/hive-196387'>STEMsocial community</a>. Feel free to join us on <a href='https://discord.gg/9c7pKVD'>discord</a> to get to know the rest of us!

Please consider delegating to the @stemsocial account (85% of the curation rewards are returned).

You may also include @stemsocial as a beneficiary of the rewards of this post to get a stronger support.&nbsp;<br />&nbsp;<br />
</div>
properties (22)
authorstemsocial
permlinkre-wwwiebe-create-a-random-word-generator-with-node-red-20230128t042938135z
categoryhive-196387
json_metadata{"app":"STEMsocial"}
created2023-01-28 04:29:39
last_update2023-01-28 04:29:39
depth1
children1
last_payout2023-02-04 04:29:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length565
author_reputation22,460,334,324,555
root_title"Create a Random Word Generator with Node-Red"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,257,481
net_rshares0
@wwwiebe ·
Thank you!
properties (22)
authorwwwiebe
permlinkre-stemsocial-rp87yn
categoryhive-196387
json_metadata{"tags":["hive-196387"],"app":"peakd/2023.1.1"}
created2023-01-29 02:52:03
last_update2023-01-29 02:52:03
depth2
children0
last_payout2023-02-05 02:52:03
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length10
author_reputation318,663,954,734,459
root_title"Create a Random Word Generator with Node-Red"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id120,282,202
net_rshares0