Video 2.3 running node red locally on your computer. In this video, we will learn why you should install Node red on your local machine, how to install and deploy node red on your local computer, be it a Windows or a Mac, and how to secure your node red editor. Now, you may have a Windows machine or a Mac machine, not to worry, we will cover both. First, we look at the installation of node red on Windows. OK, but why should we install Node red on Windows while we have already installed it on IBM, which has way more advantages than the local machine? Well, if you want to run applications in your own server, or if you want to store some data in the database running on your machine, or if you want to run applications on your machine offline Then installing node red on your local machine would be the best way.
Okay, let's start again. Yeah, there are many ways to install it, but we'll go with the simplest way. These instructions are specific to Windows 10, but should also work for Windows seven and Windows Server from 2008 or two. It is not advisable to use versions prior to Windows seven or Windows Server 2008 or two due to lack of current support. We all know that node rate runs on node j s. So the deploy node red on your local machine, we must make sure that we have Node JS. To install Node j s, go to the link I've given in the resources.
Choose the first option LTS or long term support because it's the safest bet. Make sure the downloadable link comes under Windows. Then once the installer has been downloaded the run it to install Node j s, you will be needing local administrator permissions for this. Note that NPM package manager also gets installed along with node j s. Now after the installation completes, close any open command prompts and reopen it to ensure the new environment variables are picked up. Environment Variables are nothing but dynamic objects on a computer, meaning they have an editable value, which is used by one or more software programs on Windows to know what directory to install the files in where to store temporary files and where to find user profile settings. To check if it has been installed, we can do a version check.
Go to the command prompt Again, you can use PowerShell as well, which has an advantage over command prompt because it recognizes the most basic Linux commands type the command node version and NPM version. You should see an output similar to this. Okay, now that you've installed node GS, we can install Node red using the command npm install g unsafe node red Okay, while you can understand npm install Node red What do you think G and unsafe are these are called flags. The G flag is used to install Node red as a global module, which adds the command node dash red to your system path. That is the PATH environment variable now we'll be installing node red. With the G flag enabled.
The unsafe burn flag is used to give root permissions while installing node red. This flag helps in continuing the installation in the event of an error. If you want to know what happens if you install Node red without g flag, which you should, then I have mentioned how to uninstalled node red at the end of this video, so that you can follow the video without any trouble. Check out the link in the resources, which tells you how to upgrade node red and Node JS. Once node red has been installed, and since we've installed node red as a global NPM package, use the command node dash red to start node red. In case you've installed node red without using the G flag, then you can start node red using the command node node underscore modules, backslash node hash rate, backslash red.js.
Run this command within the directory where you ran npm install. The command starts outputting node red logs in the terminal, it might take some time for setting up the node read environment. You know the setup is done. When you see the text started flows on your console. The console stays open and shows the log info of the flows, which provide a lot of information. Like you can see the versions of node red and Node JS installed on your machine.
You can also see the location of important files in Node red, and the log also shows the URL to access the web based editor. Use it to open the web based node read editor. Note that the given URL is 127 dot zero dot zero dot one colon 18. At the port number 1880 is used by note rate, which is a TCP UDP port. The IP address 127 dot zero dot zero dot one corresponds to localhost, which means instead of that URL, you can also use localhost colon 8080 to access the node red editor. One important thing to note is that to keep node rate running, we must keep the terminal open.
You can close the console by pressing Ctrl C. At first boot, the necessary directories and files like settings.gs flow file and use a directory will be created automatically. OK, okay, so what are those files? Exactly? Let me show you We have to go to dot node red, which is a hidden file. And here it is. Of these package dot Jason, and settings.js are the most important files.
I'll teach you about package dot Jason later in this course. settings.js is a settings file, which is the first to run when the node rate starts. This file sets the admin port, user directory, the flow file, etc. If you want to configure node rate, then you must go for this file. This file exports the GS object, which is what is passed through the nodes getting modified at every node. Note that these files will also be present in the IBM Cloud platform in the get repository under the DevOps tool chain.
We look into them later. You can also use your own my settings.js file instead of the default one. If you want to do that, use the switch flag while running the node red start command node dash rate dash s, my settings.js. If my settings.js was the only settings file present inside the dot node red directory, then it will be used by default. The second stage of starting node red involves setting up the user directory, which is when no dread stores all user data like credentials, flow and library data. If you want to have multiple user directories, you can mention the user directory to load in the settings.js file.
By default, the user directory chosen is dot node read the user directory contains The flow file. Okay, next is a flow file, which goes by the name flows underscore server name dot Jason. This file contains all the flows in your node read editor in JSON format for easy important export. This was created the first time you ran node red, and then every time this file gets updated when you deploy a flow the third stage of starting node red is loading flows from the flow file. The flows underscore server name underscore cred dot Jason contains the login data used by some nodes. Great.
There are other ways to manage your flows as well. You can use the project feature in the node rate, which will help you in backing up your flows using the get repository Learn how to do that, check out the resources section. Did you also know that you can run multiple instances of node read on a single machine? How? Well I don't know. But we can figure out how running different instances means that multiple users can use a single application.
Remember the URL we got 127 dot zero dot zero dot one colon 1880. You can see that the port number is 1880 where we can run only one instance of node red. Okay, so if we need to run another instance, we need to have another port number done, but it is not only the port number is it remember I told you about the user directory will the user directory will have the flow file which will contain all your flows So can the user directory be shared among different users? There is no way I'm sharing it with someone. So to avoid conflicts, we will have to have different user directories. So either you can have a different port, and a different user directory for each instance, or create and use a new settings.js file for each instance.
To check out how that works. Look for a link in the resources. Note that this is different from sharing node read with different uses of a computer. Many Node JS modules used by node red are installed nodes have binary components that will need compiling before they will work on Windows. To enable NPM to compile binaries on the Windows platform, install the windows build tools module using the command prompt as an administrator npm install global production windows build tools. Once you install the module, close and open your command prompt window for the changes to take effect, check out the link in the resources, which teaches you how to auto start node red, running on Windows on both.
Okay, now that we have a node red running, and we can access our editor to create and deploy applications, remember that according to the prophecy, the notary running on your machine can easily be hacked. Because out of the box, it is not secure. To prove the prophecy wrong, we need to secure our node red. This can be done in two ways. username or password credential based authentication, authentication against any OAuth or open ID provider, such as Twitter or GitHub. But I'm gonna go with credential based authentication.
Because it is the easiest way, we can authenticate node red platform in three ways, two of which we'll be seeing later. First, we need to secure the node red editor. For that, we need to change the settings.js file. Don't get overwhelmed by the number of code lines in this file. We will not be using much of it, but I'll explain whatever we use as in when necessary. We can secure node red editor by uncommenting, the admin author lines.
Here, you can see that there are already some credentials admin as username and password as a password, except that it is securely hashed using the bcrypt algorithm. The star denotes that the user has full access to the editor. Notice user's property is an array of user objects. This allows you to define multiple users, each of whom can have different permissions. Since everyone knows the password, it has to be changed. Add your username and password, but we have to enter the hash one.
And how can we hash it? Note rate admin comes to save the day. No dread admin is a tool to administer no dread from the command line. It provides a command to create a password hash. To use it, we have to first install it Any guess as to what the command could be? Well, it must have these keywords NPM G, node, red admin and install so let's check npm install g No dread admin.
Bingo. It is getting installed. Great. Okay, let's try the command to generate hash, no dread admin hash pw you have to enter the password to generate the hash. And there it is. Copy and paste it there and save it.
Note that whenever you change node read files, you have to restart it for the changes to take effect. So let's do it. Okay, now hopefully, we have falsified the prophecy. Let's check it to be sure. Fantastic. Now you can run your applications without worrying about your editor getting hacked.
Okay, good. Like I promised before, let me show you how to uninstalled no dread in Windows. is the same as the first command, except that the key word will be uninstalled. Instead of install. Next, you have to clean the cache by using the command NPM cache clean force G and use the command NPM LS g depth is equal to zero to check if all the modules have been uninstalled. Now we can move on to installing node red in Mac, installed Node JS the same way we installed it on Windows, then check if it has been properly installed by checking the version then run the command to install Node red.
The command is similar, but within addition sudo which will give root user access if you are not running as the root user. This command doesn't exist in Windows after installation run node dash red command to start node red, you can access the editor from a web browser. Here, you can see that there are some pre installed nodes for Mac. Anyway, if you want to add more, you can always use the Manage palette option. The dot node red folder is a hidden folder, which cannot be seen in the Mac by default. To view it, go to Macintosh HD, and hold down Command shift.to.
View hidden files and press it again if you want to hide them. Or Also, you can find the dot node red folder inside the home directory. And there you go. You have all the files, you can secure the node red editor the same way we saw in Windows. Okay, in this video, we've learned why we should integrate All no dread on your local machine, how to install and deploy no dread on your local computers, be it a Windows or a Mac, and how to secure your node raid editor. In the next video, we'll learn how to deploy node red in a single board computer.