From the course: Node.js: Microservices

Setting up and exploring your sample application - Node.js Tutorial

From the course: Node.js: Microservices

Setting up and exploring your sample application

- [Instructor] We are now almost ready to get started. In this video, we will set up our sample application that we will use as a starting point. When we look at the directory structure, you see that there is a resources directory with some helpers. I will refer to them throughout the course. And then there is a folder called workspace. So in this folder, we will be working. There is also a folder microservices, which is empty at this point. And there is this shopper application. So, the first thing I will do is I will cd into workspace and shopper. And as for any Node.js application, the very first thing is that I run npm install. Because there you see we have this package.json file with all the dependencies. We have a Redis client, MongoDB is loaded, a lot of stuff. And also OpenTelemetry, we will talk about this a little bit later. One important thing in this file is that, as you see here, we are using NodeMon. NodeMon is a little tool that restarts your application whenever you do a change. So during development, that's very helpful because you don't have to constantly reload your Node.js application. So into now use NodeMon. To start the application, I simply run npm run dev. And as you see, it says it's connected to Redis, connected to MongoDB, and the application is also listening on port 3000. With that, we have a working application. And the next thing I will do is I head into my browser, and I open localhost on port 3000 to see what is there. And you see it's a very simple application. There is not much right now, an empty shopping page. You can log in. And then there is some user management, and we will use that to create the user right away. So I create the user test at test.com. I give the user some password. Also click this button, set as admin. So in a regular application, obviously you would not want the user management to be accessible when you're not logged in. This is just here now for development purposes because somehow you have to create this admin user. So I will do this right now. And when you do this, please remember the user and the password that you created because we will need to log in later then as well. So I click submit and we have a new user. I can log in with this user. So enter test.com and enter the password and then I log in. As you see now, I have now more menu items up there. I can manage items, means I can create new items. I can manage orders, but right now we have no orders. Well, it's a shop and it's a little bit of a pity that it's empty, right? We should populate it now with some sample items. And for that, we will head into MongoDB Compass and I click the refresh button up here. And now you see that the dropper database shows up. And I open it and I head into items. And there you see this green button, Add Data. And there I select Import JSON or CSV file. And then I select from my Node microservices directory, in the resources directory, in the support directory, you find this items JSON file. And we will select this, and you see it's a JSON file full with items that we can load into our database to pre-populate it. So, I click select, and then import. Now we have 15 items imported. And when I now look into my shop, we see that we have a very simple item list. So that's not a pretty shop, but it serves the purpose. So very simple list of items. And if you wonder how I came up with these very funny item names, this was chatGPT. Now, I can also add items to my cart. And you see, when I have items in my cart, that this shows up now here on the menu bar. Then I can click on my cart. There I have now a list of all the items. And then I can finally click on buy now. And now the order is placed, and I can see this order now when I click into manage orders. So when I click into that here now, you see that there is this order now, and I can now change the order status to shipped by clicking on this red set shipped button. And this is pretty much all our sample application can do. In the next video, we will have a closer look at its code.

Contents