Analyze tweets in under 30 minutes using Node-RED

Share this post:

I created a Node-RED app in Bluemix which searches for a specified keyword, username, or hashtag phrase in the public Twitter universe whenever a new tweet is posted. This application can be created in less then 30 minutes by anyone and requires no coding experience. When a tweet is posted that matches the provided search criteria, the tweet is passed through the sentiment analysis node which returns a sentiment value.

If that sentiment value has a value less than -5 (which is a very negative tweet) then the app sends me an email with the word “tweets/” and the username who wrote the tweet in the subject header and the actual tweet in the body. This allows me to catch any very negative tweets about the search terms within a couple of seconds.

Below is an example email alert:

Quick introduction to creating Node-RED applications

A Node-RED app is created by dragging and dropping nodes—pre-written pieces of code that perform desired actions—on the left hand side of the Node-RED editor into the middle work space. The nodes are then connected by clicking the output point of one node and dragging it to the input point of another node (the little grey squares on either side of a node):

Lastly and most importantly, each node has to be given the proper parameters by double clicking on it and filling in the form that pops up:

Once those steps are completed, you click the Deploy button on the top right corner of the editor and your application will be running. Simply stated, Node-RED applications are just programmable nodes that you wire together.

My Node-RED tweet sentiment app

As shown earlier, my entire Node-RED application consists of just five nodes. The first node will search Twitter for the desired keywords entered into the form after double clicking on the node. You will need to authenticate to your Twitter username, which will allow the application to search all public tweets. To specify the search keywords fill in the “for” parameter with a word, username, or hashtag keyword that you want to retrieve all tweets containing that term (I used #testnegative as my keyword for testing purposes).

Next I added the sentiment analysis node and connected its input to the output of the Twitter node. This node will analyze all tweets that match the search term and assign them a sentiment value (this node does not need any parameters unless you want to change the name of the node itself). Average sentiment values will range from -5 to 5 with -5 being a very negative tweet, 0 being a neutral tweet and 5 being a very positive tweet. Anything outside of those ranges are extreme values and the tweets I want to capture. I then added a debug node called “debug sentiment value” to print out the sentiment value to the Node-RED debug log on the right side of the editor (this node is not required but helps to see sentiment values).

Below are some example sentiment values based on the given tweet:

  • Sentiment value of 4: #testnegative Jim’s fries is awesome!
  • Sentiment value of -3: #testnegative Jim’s fries is the worst restaurant ever!
  • Sentiment value of -4: #testnegative Jim’s fries is the worst restaurant ever! I could not pay with a debit card!
  • Sentiment value of -5: #testnegative Jim’s fries is the worst restaurant ever! I could not pay with a debit card! No one should ever go here!
  • Sentiment value of -8: #testnegative Jim’s fries is the worst restaurant ever! I could not pay with a debit card! No one should ever go here! Horrible service!

The sentiment value is then passed to a “switch” node which looks for tweets with a sentiment value that is less than or equal to -5. In the diagram above, noted that I renamed my switch node to “Analyze how negative”. If the sentiment value falls into this category, then an email is sent from my Gmail account to my work email:


That is the entire application; as you can see, there is absolutely no coding necessary. The only requirements are to drag and drop nodes, fill them out, and connect them. This app idea can be transformed in many ways. The app can be used to find very positive tweets, the app can send specified tweets containing multiple keywords to a Slack chat, the Twilio node can be integrated to have tweets be sent to your cell phone as a text, and many more implementations to analyze any tweet by anyone within a couple of seconds of it being posted. To try out Node-RED on Bluemix, go to the Bluemix Node-RED Page after you have signed up for your free 30 day Bluemix trial.

Add Comment

Leave a Reply

Your email address will not be published.Required fields are marked *

John Walicki

The sentiment analysis node outputs an additional value: msg.sentiment.score

The switch function node should evaluate the msg.sentiment.score property to determine whether the tweet is positive/negative. The article is ambiguous about which property in the switch function it should query / evaluate.


John Walicki

Thanks to @knolleary for the msg.sentiment.score property hint in his Node-RED flow posted here:
Twitter Sentiment Analysis


Ryan Ing

Hey thanks I got this working

Two issues
1. John Walicki is right in that you need to configure the switch node. You can’t just drag and drop it

2. You need to enable ‘allow less secure apps’ on your gmail for NodeRed to connect to it

More How-tos Stories

Setting Access Control Policies for IBM Cloud Object Storage

As your organization explores more digital initiatives, including cloud and mobile, the importance of identity and access management (IAM) is paramount. Nearly all IT decision makers we talk with agree that IAM is essential to the success of their company’s cloud adoption and it is seen as a key enabler for mobility, analytics and IoT initiatives.

Continue reading

Home automation powered by Cloud Functions, Raspberry Pi, Twilio and Watson

Over the past few years, we’ve seen a significant rise in popularity for intelligent personal assistants, such as Apple’s Siri, Amazon Alexa, and Google Assistant. Though they initially appeared to be little more than a novelty, they’ve evolved to become rather useful as a convenient interface to interact with service APIs and IoT connected devices.

Continue reading

New tutorials to get you started with the IBM Cloud

Looking to build your next project on the IBM Cloud and not sure where to start?

Continue reading