Hello everyone. My name is Upkar Lidder and I'm the instructor for this course developing Cloud apps for Node. js and React. js. Let's talk about the final project. Here's a scenario. You've been hired by research company to finish building a new site that uses IBM Watson services to find sentiments and emotions in text. The application was built using Express. js, Node. js in the backend and React. js in the frontend. The previous developer had to take some time off, so they have half-finished the code and pushed it to a GitHub repository and you're asked now to read through the requirements and finish the work. There's a couple of different steps here. The first step or the pre-work, is to sign up for IBM Cloud account if you haven't done so already for one of the labs and then create a Watson natural language understanding service. Now we do ask you to use this section here to claim an IBM Cloud feature code. This will help ensure that you don't get charged for any of the services that you're using for this final project and for this course. Once you have the pre-work done, you've set up all the services that you need, you will then fork GitHub repository into your own account and then use the lab environment to clone that and then finish the code that you're asked to do. I already have a clone in my GitHub account, so I'm going to grab the URL and make sure you get the HTTPS URL as that's what works in the lab environment. Now already got the lab environment open. You are probably aware of this, and I've seen this before in one of the many labs you're asked to do in the course. But essentially on the left-hand side are the set of instructions that you need to follow, and on the right-hand side is the coding environment. The first step is to forfeiture already done, and the next step is to then Git clone my repository in this environment. We're going to do that here real quick. You can see in the Explorer, I have the folder setup. The next thing it wants me to do is NPM install, the latest version. I'll do that real quick. Once that finishes. If you go NPM --version, we can clone version and installed , and they take one off. It then asking me to cd into my project directory and do an ls to see what's in there. This is the same set of folders and files that you see on the left here. Next step here is to cd into the server directory. Let's do that. Then do NPM install to install all the packages. Now you may see some warnings here. That's because the NPM version that was used to create the skeleton code is different from the NPM version that we're using here. In the package.json file, the project skeleton code requires a certain word version of Node and NPM that is not being used here. You can see that here. I mean, not to worry, it's just a warning. But on the core side we'll make sure we actually change the package.json, so you don't see this warning in the future. Let me clear my terminal real quick. Now that I've installed everything, I'll do an NPM start to start my server. You can see it started in listening on port 8080. Now, what I can do is just to make sure everything is working. I'm going to get rid of this Explorer Project, and just to make sure everything is working, I'm going to send a curl command to localhost 8080. You can see it says, "Welcome, this is a landing page of your server, it does come up." The other way to launch an application in this coding environment is to use this Launch Application button up here. We'll use this later on as well. But let me show you real quick what it does. You give it a port that you want to launch. It okay. It open to new tab, which basically has the same HTML that we see in the curl command. Good, so far. I've got my server running. Well, first it wants me to install the IBM Watson package. Let me Control C out of this. Let's do an NPM install -s, which is save. By the way, that is not required with the latest version of NPM, I could have left that out, and 6.1.1. This should install the IBM SDKs that are required in order to finish this project. Let's give that a second. Now, that's done and just as a reminder, when you install packages like that, they will eventually show up in the node modules folder. Sorry, if I go to IBM here, give it a second. Let's see, right here you see the IBM Watson module installed locally in this node modules folder. As another reminder, if had use the -g, which stands for global, able to have installed IBM Watson package in the global node namespace and not in my current project folder. Now it wants me to right-click on the sentiment analyze server and create a.env file, and this new file.env. This file will hold my credentials for the Natural Language Understanding service. If I go down here, it wants me to put this in the file. Now we'll have to get these two keys or values for these two keys from my service. Now, I do have that open in a different page. This is my Cloud account. I've got my natural understanding service already created here. Remember this was part of the pre-work. Once that loads, I will go to the Service credentials tab and instead of using what's already there, I'll create a new credentials. This is for my course, credentials, name it like that because I do want to delete it after. It's not a good idea to share your secret with other folks, but of course, I have to do this here to add it to the file, and then once I've finished this recording, I'll delete this set of credentials. I've got my API key, I'm going to copy that and paste it here. I also have my URL which is the other piece of information it needs, and I'm going to paste that here. But these two pieces of information, now my server can talk to the IBM Watson service. Now if you install this.env and we use this.env package to load that env file into our code. What do we want to do on the server side now? We've got our environment setup or configuration file setup, I should say. Then now we need to authenticate with the service using the IBM Watson SDK. We do that in the getNLUInstance method in the sentiment analyzer server. You'll see here there's a couple of lines that are commented out. Let's uncomment this line. This will actually load my configuration from the.env file. Next key here. It loads that into the process environment process.env object. In the next couple of lines, we grab the API key and the URL from the process.env object. Finally, let's add this piece of code here which helps us authenticate with the service on IBM Cloud. I'll do a quick format document that looks nicer. First thing I do is I'm creating my service instance or I'm using this package. Then I'm creating this IamAuthenticator object. Then I am creating an instance of that object by using this IamAuthenticator method passing in the API key, the service URL. Then I'm just returning the Natural Language Understanding instance back to the caller. Just as a reminder, we are working on the back-end side of the code. The next set of instructions are asking us to write four endpoints, two for emotion and two for detecting sentiments. In that subcategory, one for URL and one for text. So /url/emotion will give you emotions in a URL or the content of the URL. Then URL sentiment will give you the sentiment, text emotion will give you emotion and a piece of text, and text sentiment will give you sentiments in a piece of text. What we've done here is in the instructions we made it really easy for you. Go through the code that's been provided to you but at the end, you can copy this into the relevant portions. For example, here, it's saying add this to the URL emotion endpoint. I'm just going to use this handy copy button, and I'm going to paste this code here. Actually, I can paste it here and once more, let me just format this code. The next one I want to do is the URL sentiment endpoint. Again, let's copy this and put it in sentiment or URL sentiment. We'll do the same thing with text emotion and text sentiment. Text emotion is here and text sentiment is here. We'll go through some of this code before we run the application. Let me format one more time, a big formatting code. By the way, you can set up the editor so it formats automatically when you save. Let's save this file and see what's going on. The first endpoint here, that is saying when somebody makes a GET request to /url/emotion, you grab the URL from the request query and then we sent it off to the analyzer. We set up the parameters first, and then we sent it off to our NLU service. We get an instance from this method that we created earlier and we call the analyze method by passing in the parameters that has the URL to analyze, and we get some result back which we use promises to return to the center. This analyzed function returns a promise, and we save in the promise as resolved, then you just send the response back. If there's an error while fetching the results or while calling the service, then we send an error message back. Now this could be improved on a little bit, be it or not sending an error code here. We probably should be sending an error code, so that's for you to improve on in your spare time. The rest of the three endpoints work in a similar fashion. The only difference being here we're setting up the URL argument in this object to send to NLU, and in this case we are setting the text parameter to send to NLU.