 Okay, our application is complete. We have done all the get, the delete, the post, put in the patch endpoints. So far our data structure is just in the memory, so that's not great. Whenever we restart the application everything is reset. But for now that's okay. So now we would like to deploy it because the problem is so far we only run it in our console. We can test it but no one else apart from us can access it. It's running on our computer and whenever we shut down our computer it stops. So what you want to do is you want to deploy it on a server so that it runs 24-7 on the internet. And we use Heroku here. As I mentioned it has three options so it's really great for experimenting. There are of course many more cloud services so AWS, the Azure, Microsoft cloud. There are countless options as Google. They are usually, they can be very confusing in the beginning. And so you need to get used to that but down in the principles they're all the same. So let's maybe start off by looking at what Heroku has to offer as we do not need. So if you just go to Heroku you can do a free sign up. I have already logged in so I can see different things. But you see all my different applications that are running and you can create a new one. So I think there is a limit, a certain number of things that can run but for testing this is good enough. You can also see that my applications run in different locations. They run with different programming languages so it's Node.js. I have some stuff in Python and you can do all these different things. If we go into any of them, for example this one I have no idea what's running here. You can see that there are a number of configurations you can do. For example Dynos that's basically the process, the application that is running. You can change that so there are different options and then they start costing. So there are different things. For example the free version what happens is when you don't use it for a time it starts getting inactive. It starts sleeping and then the next time you call it it takes a couple of seconds to start up. So that's something you don't want to have in a professional environment but it's a good start. You have add-ons so here for example you could add a database. If I search for Mongo you find the MongoDB plug-in that I'm using. Again there are free options and there are all sorts of different things you can add. Some of them are for free, some of them are not. We'll start off without anything. We'll later on add the MongoDB database. And then there are all sorts of other things that might be useful. So you can say how do you actually deploy this? And again this is the reason I'm using Heroku because it's extremely easy to deploy using Git using the command line. And then there are for example metrics that measure how has the activity been and so on. So you can do this. Again they are only available in this case for subscriptions that cost. But then you can add measurements which is of course very useful. You see the deploy activity and so on. So that's what you can do. And the deployment in Heroku is as I said very easy. You have a command line interface that you can install and that's something you need to do. The other thing is you need to install Git if you haven't done that. It's a very popular version control system. You definitely need to get used to that because it's the standard that you'll use all over the place. So if you haven't, get familiar with Git. Even though for this course you don't need a lot of knowledge in it. So it's fairly easy. If we want to deploy and we'll just try this out. You have to create a new application in Heroku and then you basically have to follow these commands. So you have to initialize a new Git repository. You have to add the files that you want to add. You have to commit them and then you deploy. So this is what we'll do. What I have created here is a folder deployment. And in this folder I have just copied our application. That doesn't have anything. It's exactly the same that I've just shown previously where all the endpoints are implemented. Nothing else. And this I can deploy but then nothing happens. Because I also need a JSON file that tells me what exactly needs to be installed. So I need to have a JSON file with the right name. The main script is called to do all NP. I have added a start command. That really does not matter. This just means that instead of doing note this file I can just run npm start. So that's nice to have. I can add myself as an author. I don't know if this is the right dependency. So let's add it again. NPM install express save. And I probably need more dependencies. I also need the body parser. So let's add that one as well. And now we can do exactly what's written in the website I just showed you in the instructions. So I initialize my repository. I add all the files I want to add. And that's my JavaScript file. And it's my package.json. Do not add the node modules or the package log. These are created automatically. And especially the node modules is huge. So it takes forever if you want to add all of that. Then I commit. Initial commit. This is done. And now I go in and I use my Heroku command line interface to actually create a new application. The first thing you have to do is do Heroku login. I have already done that here. Which just makes sure that you are actually logged in and you're allowed to use this. So now if I do Heroku create, it starts creating a new thing. And now I already have an internet address and host address. It's hdbsfierscastle63539.herokuapp.com. You can give these better names by the way. So I don't have to have that. If I go there nothing will happen because I have not deployed anything. So that's what happens next. Now Heroku has added automatically the right Git repository to my Git here. So I can now continue. And I can deploy my code. So I can do just the Git push to the Heroku master. If I spell it correctly it should work. So now it starts pushing the code up on the repository. And it says build succeeded. And you see that it actually runs npm install. So it detects automatically that this is a Node.js project. It installs the right modules, 50 packages. And it deploys. And now if we reload probably nothing will happen. We'll see. It depends on how smart Heroku is. You see it takes a while. Something is trying to get to work. And you see that there are also other options. For example deploying branches and so on. So you can look at that later on. So there is a lot of stuff you can do otherwise. Now here nothing is happening. And the main reason for that most likely is because we haven't told Heroku how to start our application. And that's actually something that out of some reason it does not detect automatically. So what we'll have to create is another file. And you can search that in the Heroku documentation. So you can just say deploy Node.js. It will probably tell you how exactly to do that. So it says what do you need. And there's one thing we need. And that is a so-called proc file. So what Heroku is looking for is a file that tells Heroku how to start. What to start. And that file in our case looks very, very easy. So we'll just go into that and create it. So you just go into your deployment folder. You create a new file and you call it proc file. Important is that the P here is actually capital. And now we just tell the script run npm start. And now there's actually something I need to look up because I never remember the details. Whether I need the quotation marks or not. No, I do not need them. And that's all it is. You just need to tell Heroku run npm start whenever this is being started. So the web process in Heroku is just a specific type that can receive external HTTPS traffic. So whenever you have a web server, which is what we do in our case. We want to receive HTTP requests and answer them. So we just tell Heroku for this web process, please use the following command. And now I add this file and I just commit again. Add a proc file and I push to master. And now Heroku does the same thing again. It installs Node.js. It runs npm start. And it compresses and then it starts the application. So deployed. Let's have a look whether this is better now. There might be still things that I have missed. We'll see. We'll see what I have actually removed my start script. No, it's still there. So this should work. Dependencies are there. The proc file is there. So typically this should work. Then there's always something you forget. So we'll see what Heroku comes up with. So it does not seem to work. And now the interesting question is what has happened. And you could maybe try to find that in the access or somewhere in the logs. Here you see application error. Check your logs for details. And this is not an important thing because we don't have our command line here. So here nothing is running so you cannot check if there's an error. And one way to access the logs is to use again the Heroku command line interface to just get the right information. So we want to use Heroku logs, for example, from our app Fierce Console. And you see that it has been started. It's listening. Why is it not working? Now one thing that has happened here is that we have assigned port 3000. Here we go. We tell the express application, please run on port 3000. This is a typical example for stuff that happens when you deploy things on another server. This might not be in agreement with what Heroku wants you to do. So Heroku, and it's the same with most other cloud providers, have specific settings for where should your application run. We already have one. We already have told Heroku on your specific web process. Please start the application. That makes sure that it actually runs on the right IP address and so on. We don't have to care about it. But the other thing is the port. We have to figure out what is the port if you want us to run this. And there might be an option to go into the documentation, find the right port number and then write it in here. What is much more common is to use environment variables. Again, this is something that you have in pretty much all cloud deployments are config variables. So I can set them myself. I can set variables and we'll get to why that is useful. But there are also some that are included. And in our case, Heroku has a config variable for the port. So we can just access the port using config variables. Let's see whether we find it here. No, we don't. If not, then I have it somewhere else in one of my other applications. So this is again something you need to find out in the documentation. So what we do here is we say try to access the environment variables. So that's something that the operating system sets. In our case, Heroku does that and check whether there is a variable called port. If this is undefined, then the or kicks in and we assign 3000. So this means that if I run the application locally on my machine, this will be ignored and the application runs on 3000 as usual. If port is defined, then we just run the application there instead. So this variable should look differently. Now let's try this. I've changed my application, so I need to push it again. And as you have seen or as you have not seen rather, there was no error here. So there was no problem. It has run my application on port 3000. The problem is just that the configuration in Heroku is in such a way that port 3000 is simply not reachable from the outside. So the application was running. I could just not access it. Now let's see what the logs say. Now you actually see that it runs on some other port, some pretty strange port. And that's what Heroku has defined. So it has said this is the port you need to run the application on. And now finally, if I run it again, or if I access it again, you see that I get operation not supported. This is actually what I want. So if I do slash users, I get Alice in Bomb. And now the difference, the important difference is this application runs on the internet. So all of you could access this. I don't have it only on my computer. So there's a big difference here. And it runs 24 seven. Of course, as I said, this is the free version. So it goes to sleep at some point. If I would pay for this, then it would really run nonstop. And of course, this URL is maybe not very practical, but for that you then have to buy a domain. So if you want any nicer name that points to this location, you need to pay and get a domain. So that's the deployment thing. As we have seen, there are a couple of things we need to look at. We need to figure out how to push our code. We need to have a certain adaptation. For example, in our case, we needed to find out what is the right port number. We needed to add the proc file. So the file that tells Heroku how to run our application. And then we needed to push all of that. So that's how the deployment works. And now in the final step, we'll add a database. So we'll finally get away from our local storage here. So this one is kind of refreshed every time I restart the application. We'll now use a database to actually save this.