Section three note rate nodes. In this section, we will learn how to use the different nodes present in the node red palette, video 3.1. js, regular expressions, Jason, and Jason data primer. In this video, we will be looking at the basics of JavaScript, regular expressions, Jason, and the query language for Jason Jason data. We will start with the JavaScript. I'll be assuming that you're already familiar with other programming languages. And you know the basics of programming.
We've already seen what is JavaScript in section one. So now you must be able to answer my question. Why are we using JavaScript here? Yes, it is because no dread runs on node j s, which is a runtime environment for executing JavaScript code. Good work for those who gave the right answer. If you haven't got this right not to worry, everything will become clear as the course progresses.
To learn a programming language, we need an editor to experiment with that language. Since all browsers run a JavaScript environment, you can use any one of them to experiment. I'll be using the chrome v eight JavaScript engine to execute my code. That is, I'll be using the Chrome browser to experiment my JavaScript code. If you are following me, then you can either use the console which is an RDP l environment, or you can run JavaScript as a.js file under the sources tab. I have explained the basics of GPS in a PDF file attached to this lecture.
Please go through the document before proceeding further with this video. Now that you're familiar with all the basics, we'll move on to some complex stuff. We learn about objects. As you would know by now, it is also one of the data types in JavaScript. in JavaScript, other than the primitive data types, all other values like arrays, functions, regular expressions, and of course, objects are objects. Unlike other programming languages, objects in JavaScript are class free.
I'll explain how that works. An object has different properties in the form of key value pairs, it can have arrays, functions, and objects themselves. Let us look at an example. object. Here, we have initialized an empty object. In the next line, I have added a property called text with the string Hi.
In a classic initialization of object in other languages, the class will have the properties and methods predefined, and the objects will be an instance of the class. And so we cannot add new properties to the object on the go. Instead, we can only create a new class. But here in JavaScript object properties can be modified on the go, which is what makes it special. You can add any value with any name at any time to the object like this. And now, when we check the object, you can see that there are two properties.
You can also create a new object by using the command Knew like this. Okay, you may think I understand that. But how do I access the value of an object? How can I modify it? You can do that in two ways, using the dot notation and the bracket notation. In the documentation, you can say, object dot txt to access the value of the text property.
You can rewrite it by initializing it again. And now the object will be updated. In a bracket notation, we can access the property number like this. But why two notations? Well, bracket notation utilizes string values. It allows for the use of characters that otherwise would be a violation of the syntax.
Let's try it out. grid it works. Did you notice something, an array, a specialized descendant of the JavaScript object as in teachers as key for any key value pair, and because of that, we have to use bracket notation, rather than the dot notation to access them. Although the keys have an array and numerical, behind the scenes, each integer is coerced into its string representation. There are some JavaScript native objects like number, Boolean string, array, date, math and regular expressions. We will be using them whenever it is necessary.
So you need to know what they are and how to use them. And for that, go through the respective link in the resources. Okay, now let us come back to the Ice Cream Factory annelle To remember, the message object as the trolley with payload as the ice cream and other properties like topic and underscore message ID imprinted on the trolley. I'll first explain what exactly is a message object. The message object is the standard JavaScript object and has several existing properties depending on where it originates from. In the last example, we saw the one using the inject and debug node.
It had three properties because it originated from the inject node. The properties were payload topic and underscore message ID. The payload contain the text ice cream, the underscore message ID and the message identifier, which is used to track message objects and the topic property would contain the topic if we had initialized it in the inject node If it had originated from a different node, then it might have different properties. Like we saw here, we can add new properties to our message object. We can modify it, we can even delete properties. This is one of the main reasons why java script was chosen to develop node red.
In the upcoming videos, we will be learning how to use nodes to modify this message object as per our application. Okay, now that we clear about JavaScript objects, let us move on to regular expressions. Regular expressions, yes, think about this. You're going to analyze emails or tweets. And if it had a key word like no dread, then it needs to be retweeted. This is a whole application.
We are Planning to create. Let's take the analyzing tweets part alone. Here, you have to search for the word no dread in every tweet having many lines right. You can do that manually by reading through every line of hundreds of tweets per minute. If you're too bored, or a simpler way would be to use regular expressions. Regular expressions consists of a sequence of characters which form a search pattern, which is used for the text search and text replace operations.
You can define regular expressions in two ways. One is using the regular expression native object we saw before like this, where pattern is equal to new regular expression pattern, comma modifiers. Or simply where pattern is equal to slash patterns slash modifiers. As you can see, there are two parts to a regular expression, pattern and flags. All modifiers now will give you a basic idea of how to write patterns, after which you need to go through the link I have given to know more about the regular expressions and methods used in them. In regular expression, the syntax defines the expressions.
To try out regular expressions, go to the link I've given in the resources. This is the place where you write your expression. You can define the flags here. The text to be tested should be written here. And here, you have different options to help you out. There is also a reference doc on your right in case you need help.