-
Started by initializing a new Node.js project and installing Express.js to create your backend server. You can use npm init to initialize your project and npm install express to install Express.js.
-
To start and run the Server use this command
npm install && npm run dev
-
To test the app use this command
npm test
-
Created routes for CRUD operations (Create, Read, Update, Delete) for managing todo items.
-
Implemented corresponding controller functions to handle these operations.
-
Implemented user authentication middleware using JWT (JSON Web Tokens).
-
Created routes for user registration and login,
-
Utilized JWT to generate tokens upon successful authentication and verify tokens on protected routes.
-
Set up a Node.js project and install Express.js.
-
Defined routes, middleware, and controllers to handle API requests.
- [authRoutes.js]
- [todoRoutes.js]
- [todoSchema.js]
- [userSchema.js]
- [authentication.js]
- [error-hanler.js]
- [not-found.js]
- [auth.js]
- [todoController.js]
- Choosen a Mongo Database to store data
- Set up a connection to the chosen database MongoDB using a suitable Node.js library using Mongoose for MongoDB.
- Defined database models for storing todo items and user information.
Created endpoints for performing CRUD operations on todo items. Defined routes for creating, reading, updating, and deleting todo-items, and implemented corresponding controller functions to handle these operations.
- Written unit tests and integration tests for API endpoints using Jest.
- Mocked dependencies such as database operations and external services.
- Tested authentication flows, CRUD operations, error handling, and edge cases.
-
Written a Dockerfile to define the application's environment and dependencies.
-
Build a Docker image for the application.
-
Note - I have used local environment URL (mongodb://localhost:27017/mydb.todo-auth) for MongoDB in dockerfile
- Set up Continuous Integration (CI) pipelines to automate testing.
- Used a CI/CD platform (e.g., GitHub Actions) to trigger builds and tests on code changes.
- Configured deployment pipelines to deploy the application to staging and production environments.
- Hashed user passwords before storing them in the database using a strong hashing algorithm (e.g., bcrypt).
- Stored JWT secret securely and rotate it periodically.
- Added pagination and filtering parameters to relevant API endpoints.
- Implemented logic to paginate through large datasets and filter results based on criteria provided in the request.
- Docgen Library
- Export Postman Collection
- Make sure the postman's collection and windows_amd64.exe should reside in same folder
- Run below command using command prompt
- windows_amd64 build -i todo_crud-apis-auth.postman_collection.json -o index.html
- A index.html file will be generated then place place that file under public folder
- Use this code to host static html file
server.use(express.static('./public'));