From the course: Learning End-to-End Testing with Jest
Template: Node.js/Express project setup
From the course: Learning End-to-End Testing with Jest
Template: Node.js/Express project setup
- [Instructor] For this course, I have prepared for you a template Node.js project recipe app, which is a simple REST list service, which provides, lists, creates, read, updates, and deletes functionalities to a log-in user. This project is on GitHub, and can be accessed at the URL highlighted. You are also free to use any of your own Node.js projects. Any which way, just make sure to practice along with me. Let's get it installed. For you to successfully set up this project on your local machine, you need to have GIT, Node.js, and MongoDB installed on your machine. I have mine installed. If you don't have yours installed, pause this video, download and install them, and let's get this project set up on our desktop directory. Now that you have GIT, Node.js, and MongoDB installed, open your terminal, navigate into your desktop directory, by running the command, "cd desktop". Now, clone a copy of our template project by running the command, "git clone --branch", the branch name, "02_01b", followed by the URL. We have successfully created this template project on our local computer. So, let's go ahead and open it in our code editor. I am using Visual Studio Code, and it has an input terminal. Henceforth, I'll be using the Visual Studio Code input terminal, instead of the usual terminal. Run "npm install" in your terminal to install all the package dependencies. If you are using the normal terminal, remember to cd into your template's project directory before running this command. Next, let's set up our environment variable. Find the ".emv.example" file, duplicate it, and rename it duplicate to ".emv", then, update the access token and the MongoDB URL, accordingly. Access token can be any random numbers and alphabets, and MongoDB URL is "mongodb://localhost:27017/recipe_app"... Finally, run "npm run seed", to seed some data to the database, and "npm run start", to start the application. Great! Our sample project is running. Let me walk you through the project for better understanding. This is the "package.json" file, which holds the various metadata relevant to our project. It shows the main is the "index.js" file, which listens to our express server on port 8080. We used the model-routes-controllers-service code structure. This is our route's "index.js" file, with six endpoints. The right endpoints have JWT authentication. What I mean by right endpoints are: Endpoints that make changes to your database, like, the endpoints for creating, updating, and deleting recipes from the database. When an endpoint is called, it calls its controller, but the right endpoint has to pass through the JWT authentication middleware, first, to ensure the user is authorized, before making a call to the controller. The controller is where the logic sits, and it makes a call to the service file to perform specific data service. The controller receives a request from an endpoint, and returns a response to it. In the database folder, we have the database connection file. This file creates the database connection that is used in the models where the database schema is created. Because we are conscious about good code quality, we used ES Links to ensure our code is consistent. Now, you have a functional project, we are ready to begin testing.