This challenge deals with the development of a Back-end application in Node.js using Express, applying the principles of Object-Oriented Programming (OOP
) to build an API with CRUD
to manage a car dealership. This will be done using the MongoDB
database.
Following MSC
software architecture (Model - Service - Controller) and REST
web architecture principles, connecting to a MySQL
database for information persistence.
- For the development of the application, I chose to use
Node.js
technologies, as it is an engine (engine) already based onJavaScript
, widely supported and with non-blocking IO (using async methods for stacks), withExpress
, which is a mature framework and tested, which provides a number of useful abstractions for building HTTP APIs inNode.js.
This is because they are tools where I have solidified knowledge and domain, thus enabling an agile and safe development of the entire project; - The software architecture chosen was the
MSC
(Model - Service - Controller) as already mentioned in the introduction, as it is a layered architecture model, which improves the organization and division of responsibilities inNode.js
applications withExpress
; - The database chosen for the persistence of information was
mongodb
, which is a document-oriented database and was designed to store a large scale of data, in addition to allowing you to work efficiently with large volumes. Its advantage is the permission to create multiple databases and multiple collections within the main one. - For the tests, considering the application in
Node.js
withExpress
, I opted for the triadChai
(for assertions, providing ways to tell the code what I expect, test and validate the return),Mocha
(as framework/base “describe / it ” tests for JS) andSinon
(which provides the functions for test doubles or test doubles, simulations of code interactions with dependencies external to it), since they are established tools and also where I present full knowledge and domain. - As a tool to ensure code compliance, standardization and quality, I used
ESLint
.
-
The application had 100/100% of all its main functionalities tested, in all layers and always considering the success and error cases.
If you don't have MongoDB installed on your machine and want to use Docker, just follow the steps below:
- Download the MongoDB image:
docker pull mongo
- Create the MongoDB container:
docker run --name <container-name> -p 27017:27017 -d mongo
- Check if the container is running:
docker ps
Run the
node
andmongodb
services with the commanddocker-compose up -d
.
- Remember to stop
mongo
if you are using it locally on the default port (27017
), or adapt if you want to make use of the application in containers - These services will initialize a container called
car_shop
and another one calledcar_shop_db
. - From here you can run the
car_shop
container via CLI or open it in VS Code.
Use the command
docker exec -it car_shop bash
.
- It will give you access to the interactive terminal of the container created by compose, which is running in the background.
Install dependencies [If any] with
npm install
⚠ Attention ⚠ If you choose to use Docker, ALL the commands available in package.json
(npm start, npm test, npm run dev, ...) must be executed INSIDE the container, that is, in the terminal that appears after executing the docker exec
command mentioned above.
⚠ Attention ⚠ The git inside the container is not configured with your credentials. Either do the commits outside the container, or configure your git credentials inside the container.
⚠ Attention ⚠ Do not run the npm audit fix command! It updates several project dependencies, and this update conflicts with the evaluator.
✨ Tip: The Remote - Containers
extension (which will be in the recommended extensions section of VS Code) is indicated so that you can develop your application in the Docker container directly in VS Code, as you do with your local files .
Install dependencies [If any] with
npm install
✨ Tip: To run the project this way, you must have node
installed on your computer.
✨ Tip: The evaluator expects the node
version used to be 16.
go to http://localhost/3001/docs