This server-side project embodies my extensive knowledge of backend development, as it has been executed with adherence to best practices, standards, and strict guidelines.
This server side project stores data in the database and makes it accessible with REST APIs, that are written in NodeJS and typescript language, with express ts for the server.
The project includes the following APIs :
For authentication and users | For recipes data |
---|---|
+ Register user | + Get recipe by name |
+ Login user | + Get list of all the recipes |
+ Logout user | + Get recipes list by query filters and sortable data |
+ Update user's data | - Authentication is required |
- Authentication is required | - Pagination included in the response |
+ Create a new recipe | |
- Authentication is required | |
+ Update existing recipe data | |
- Authentication is required | |
+ Delete existing recipe | |
- Authentication is required |
In addition, the project boasts extensive Swagger API documentation, covering all the REST APIs mentioned above, accessible at:
http://localhost:3000/swagger
NOTE:
Certain APIs necessitate authentication, requiring users to log in before executing them. These authenticated APIs are denoted by a lock symbol.
Requirements
- NodeJS version 16.4+
- MongoDB service version 6.0.1+
Command lines
- The command to init and install project
npm install
- The command to run the project
npm run start
(executing migrations, building the TypeScript code, and running the compiled JavaScript project)
- Additional commands that are optional
npm run migrationDB
(runs only migration)npm run dev
(runs typescript code for development with nodemon)npm run test
(runs only tests with jest + supertest for APIs tests)
- Nodejs : the project is javascript based.
- TypeScript : the project has been implemented using typescript interfaces,
<filenames>.d.ts
declarations files, etc.. - Express : used for the server side routers, middlewares, controllers, and services.
- MongoDB : utilized with the mongoose library for defining schemas and models, which are then utilized in the controllers and services.
- Passport : authentication with passport-local strategy
{username, password}
for request body. - Bcrypt : user passwords are securely encrypted in accordance with best practices to ensure data security.
- Migrate-Mongo : the migrations ensure that the MongoDB database has the latest updates of the data before running the project, they also handle important database initializations, including user creation and mocked recipes.
- Swagger : the
/swagger
URL provides comprehensive API documentation and instructions for testing and debugging APIs,this functionality is available in non-production environments (for development), the project also utilizes mongoose-to-swagger to transform mongoose models into Swagger schema docs. - Logger : utilizes colorized Winston logs with request ID (UUID) for recording server activities stored in daily rotating files (winston-daily-rotate-file).
- DotEnv : utilizes dotenv files to manage environment variables, and incorporates dotenv-expand to enhance flexibility in the env files.
- ESLINT : the project adheres to the ESLint guidelines and follows the best practices recommended by airbnb.
- Jest : Comprehensive typescript tests for thorough validation of all services and functions with full tests coverage, including password encryption, models, services, and router APIs, have been implemented using the supertest package.
- Mongodb-Memory-Server : running tests on an in-memory database, allowing for efficient and isolated testing.
- Nodemon : watches for typescript file changes and compiles them in real-time.
-
RESTful APIs : this server-side project includes RESTful APIs that follows best practices in API design , facilitate efficient data retrieval and manipulation through well-designed endpoints, promoting effective server communication.
-
Aggregations : a fully featured aggregate request filters recipes based on query parameters, populates the recipe by its creator, and supports data limiting, offsetting, and sorting options.
-
Server Side Pagination : the project implements pagination for the aggregation result data, enabling fetching a limited number of items based on the provided page number and items per page parameters.
{ "pagination": { "totalItems": 487, "page": 5, "itemsPerPage": 20, "totalPages": 25 }, "data": [...] }
-
Mongoose schema hooks : incorporates a pre-save hook that encrypts the user's password before creating a new user.
-
HTTP Status Codes : HTTP request responses return the appropriate and correct status codes.
-
Override toJSON data : exclude the password from the user object when it is returned as JSON.
-
Postman collection : postman collection for simplified testing and interaction with the project's APIs :
cooking-recipes-server-rest-api.postman_collection.json
Afek Sakaju
- LinkedIn: @afeksa
- GitHub: @Afek-Sakaju