{"id":26235680,"url":"https://github.com/dxtaner/e-commerce-backend-nodejs","last_synced_at":"2026-04-10T12:04:38.044Z","repository":{"id":218497002,"uuid":"746545628","full_name":"dxtaner/e-commerce-backend-nodejs","owner":"dxtaner","description":"e commerce backend","archived":false,"fork":false,"pushed_at":"2024-04-23T05:29:32.000Z","size":2165,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-23T09:49:36.695Z","etag":null,"topics":["async-await","ecommerce","expressjs","jsonwebtoken","jwt-authentication","mongoose","testing","validators"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dxtaner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-01-22T08:18:02.000Z","updated_at":"2024-02-12T19:32:40.000Z","dependencies_parsed_at":"2024-02-01T12:07:21.161Z","dependency_job_id":null,"html_url":"https://github.com/dxtaner/e-commerce-backend-nodejs","commit_stats":null,"previous_names":["dxtaner/e-commerce-backend-nodejs"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxtaner%2Fe-commerce-backend-nodejs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxtaner%2Fe-commerce-backend-nodejs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxtaner%2Fe-commerce-backend-nodejs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dxtaner%2Fe-commerce-backend-nodejs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dxtaner","download_url":"https://codeload.github.com/dxtaner/e-commerce-backend-nodejs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243330318,"owners_count":20274039,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async-await","ecommerce","expressjs","jsonwebtoken","jwt-authentication","mongoose","testing","validators"],"created_at":"2025-03-13T03:17:20.843Z","updated_at":"2025-12-26T12:34:56.423Z","avatar_url":"https://github.com/dxtaner.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Express.js Application with Compression Middleware\n==================================================\n\nThis is a basic Express.js application with compression middleware to improve response time. The application also includes a main router for handling API routes.\n\nGetting Started\n---------------\n\n1.  Install the necessary dependencies:\n\n    npm install\n\n3.  Start the Express server:\n\n    npm start\n\nThe server will be running on [http://localhost:3000](http://localhost:3000) by default.\n\nDependencies\n------------\n\n*   [Express](https://expressjs.com/): Fast, unopinionated, minimalist web framework for Node.js.\n*   [Compression](https://www.npmjs.com/package/compression): Middleware for compressing responses.\n\nApplication Structure\n---------------------\n\n*   **Main Router:** The application includes a main router (`MainRouter.js`) for handling API routes. You can find and customize the routes in this file.\n*   **Middleware:**\n    *   `compression`: Used to compress responses, reducing the size of data sent to clients and improving performance.\n    *   `express.urlencoded` and `express.json`: Middleware for parsing incoming request bodies.\n*   **Default Route:** The default route (\"/\") responds with a simple message: \"Hello, My App!\"\n\nAPI Routes\n----------\n\nAll API routes are prefixed with \"/api\". You can define and extend the routes in the `MainRouter.js` file.\n\n\nReal-Time Product Updates with Socket.io and MongoDB\n====================================================\n\nThis repository contains a Node.js application that demonstrates real-time product updates using Socket.io and MongoDB. The application uses a WebSocket connection to notify clients about changes to product data in the MongoDB database.\n\nPrerequisites\n-------------\n\nBefore running the application, make sure you have the following installed:\n\n*   Node.js\n*   MongoDB\n*   npm (Node Package Manager)\n\nInstallation\n------------\n\n1.  Clone the repository:\n\n    git clone[ https://github.com/your-username/real-time-product-updates.git](https://github.com/dxtaner/e-commerce-backend-nodejs)\n    cd real-time-product-updates\n\n3.  Install dependencies:\n\n    npm install\n\n5.  Create a `.env` file in the root directory with the following content:\n\n    PORT=3000\n    MONGODB_URI=your_mongodb_connection_string\n\nReplace `your_mongodb_connection_string` with the actual connection string for your MongoDB database.\n\nRouter Configuration\n====================\n\nThis repository contains a set of routers built using Express.js for handling various endpoints of an application. Below is an overview of each router and its purpose:\n\nRouters\n-------\n\n1.  ### Auth Router\n    \n    Path: `/auth`\n    \n    Handles authentication-related endpoints.\n    \n2.  ### User Router\n    \n    Path: `/user`\n    \n    Handles user-related endpoints, requiring authentication.\n    \n3.  ### Product Router\n    \n    Path: `/product`\n    \n    Manages endpoints related to product operations, requiring authentication.\n    \n4.  ### Cart Item Router\n    \n    Path: `/cartitem`\n    \n    Responsible for managing shopping cart items, requiring authentication.\n    \n5.  ### File Router\n    \n    Path: `/file`\n    \n    Manages file-related endpoints, requiring authentication.\n    \n6.  ### Search Router\n    \n    Path: `/search`\n    \n    Handles search functionalities.\n    \n\nMiddleware\n----------\n\n*   ### AuthValidator\n    \n    Location: `../validators/AuthValidator.js`\n    \n    Provides authentication checks for routes requiring authorization. Used as middleware for routes handling user, product, cart item, and file operations.\n    \n## Auth Router\nThis router handles authentication-related endpoints.\n\n### Endpoints\n\n1. **Login**\n   - Path: `/auth/login`\n   - Method: `POST`\n   - Description: Authenticates a user.\n   - Request Body:\n     - Requires validation using `UserValidator.loginValidator`.\n     - Should include user credentials (e.g., email and password).\n   - Controller: `AuthController.loginController`\n\n2. **Register**\n   - Path: `/auth/register`\n   - Method: `POST`\n   - Description: Registers a new user.\n   - Request Body:\n     - Requires validation using `UserValidator.registerValidator`.\n     - Should include user details (e.g., username, email, password).\n   - Controller: `AuthController.registerController`\n\n## User Router\n\nThis router handles user-related endpoints.\n\n### Endpoints\n\n1. **Get User**\n   - Path: `/user/:objectId`\n   - Method: `GET`\n   - Description: Retrieves a specific user by object ID.\n   - Request Parameters:\n     - `objectId`: The unique identifier of the user.\n   - Middleware:\n     - `UserValidator.getUserValidator`: Validates the request parameters.\n     - `UserValidator.validate`: Additional validation if needed.\n   - Controller: `UserController.getUser`\n\n2. **Get All Users**\n   - Path: `/user`\n   - Method: `GET`\n   - Description: Retrieves all users.\n   - Middleware:\n     - `UserValidator.getAllUsersValidator`: Validates the request.\n     - `UserValidator.validate`: Additional validation if needed.\n   - Controller: `UserController.getAllUsers`\n\n## Product Router\n\nThis router handles product-related endpoints.\n\n### Endpoints\n\n1. **Add Product**\n   - Path: `/product/`\n   - Method: `POST`\n   - Description: Adds a new product.\n   - Request Body:\n     - Requires validation using `ProductValidator.addProductValidator`.\n     - Should include product details.\n   - Controller: `ProductController.addProductController`\n\n2. **Edit Product**\n   - Path: `/product/:objectId`\n   - Method: `PUT`\n   - Description: Updates an existing product.\n   - Request Parameters:\n     - `objectId`: The unique identifier of the product to be edited.\n   - Request Body:\n     - Requires validation using `ProductValidator.editProductValidator`.\n     - Should include updated product details.\n   - Controller: `ProductController.editProductController`\n\n3. **Get All Products**\n   - Path: `/product/`\n   - Method: `GET`\n   - Description: Retrieves all products.\n   - Controller: `ProductController.getAllProductController`\n\n4. **Get Product**\n   - Path: `/product/:objectId`\n   - Method: `GET`\n   - Description: Retrieves a specific product by object ID.\n   - Request Parameters:\n     - `objectId`: The unique identifier of the product.\n   - Middleware:\n     - `ProductValidator.getProductValidator`: Validates the request parameters.\n   - Controller: `ProductController.getProductController`\n\n5. **Delete Product**\n   - Path: `/product/:objectId`\n   - Method: `DELETE`\n   - Description: Deletes a specific product by object ID.\n   - Request Parameters:\n     - `objectId`: The unique identifier of the product to be deleted.\n   - Middleware:\n     - `ProductValidator.deleteProductValidator`: Validates the request parameters.\n   - Controller: `ProductController.deleteProductController`\n\n## Cart Item Router\n\nThis router handles cart item-related endpoints.\n\n### Endpoints\n\n1. **Add Item to Cart**\n   - Path: `/cartitem/`\n   - Method: `POST`\n   - Description: Adds an item to the cart.\n   - Request Body:\n     - Requires validation using `CartItemValidator.addItemToCartValidator`.\n     - Should include item details.\n   - Controller: `CartItemController.addItemToCart`\n\n2. **Get Cart Items**\n   - Path: `/cartitem/`\n   - Method: `GET`\n   - Description: Retrieves items from the cart.\n   - Middleware:\n     - `CartItemValidator.getItemsValidator`: Validates the request.\n   - Controller: `CartItemController.getCartItems`\n\n3. **Get All Items**\n   - Path: `/cartitem/all`\n   - Method: `GET`\n   - Description: Retrieves all items from the cart.\n   - Middleware:\n     - `CartItemValidator.getItemsValidator`: Validates the request.\n   - Controller: `CartItemController.getAllItems`\n\n## File Router\n\nThis router handles file-related endpoints.\n\n### Endpoints\n\n1. **Upload File**\n   - Path: `/file/upload`\n   - Method: `POST`\n   - Description: Uploads a file.\n   - Request Body:\n     - Requires a single file upload using `multipart/form-data` format.\n   - Controller: `FileController.uploadFile`\n\n2. **Get File**\n   - Path: `/file/:filename`\n   - Method: `GET`\n   - Description: Retrieves a specific file by filename.\n   - Request Parameters:\n     - `filename`: The name of the file to be retrieved.\n   - Controller: `FileController.getFile`\n\n3. **Get All Files**\n   - Path: `/file/`\n   - Method: `GET`\n   - Description: Retrieves metadata for all files.\n   - Controller: `FileController.getAllFiles`\n\n## Search Router\n\nThis router handles search-related endpoints.\n\n### Endpoints\n\n1. **Search**\n   - Path: `/search/`\n   - Method: `GET`\n   - Description: Performs a search operation.\n   - Controller: `SearchController.searchController`\n\nUsage\n-----\n\n1.  Clone the repository.\n2.  Install dependencies using `npm install`.\n3.  Start the server using `npm start`.\n4.  Access various endpoints using the provided paths and ensure authentication where necessary.\n\nAuthentication\n--------------\n\nAuthentication is required for routes handling sensitive operations such as user management, product management, cart operations, and file handling. The `AuthValidator` middleware ensures that only authenticated users can access these routes.\n\n\nUsage\n-----\n\n1.  Start the MongoDB server.\n2.  Run the application:\n\n    npm start\n\n4.  The server will be started at the specified port (default is 3000). Open your browser and navigate to [http://localhost:3000](http://localhost:3000) to access the application.\n\nWebSocket Connection\n--------------------\n\nThe application uses Socket.io to establish a WebSocket connection between the server and clients. When a client connects to the server, it joins a room specified by the product ID.\n\n    // Example: Joining a room based on the product ID\n    socketio.on(\"connection\", (socket) =\u003e {\n      socket.join(socket.handshake.query.productId);\n    });\n\nReal-Time Product Updates\n-------------------------\n\nThe application listens for changes in the MongoDB database using change streams. When a product is updated in the database, the server emits a `product-update` event to the corresponding room, notifying clients about the change.\n\n    // Example: Broadcasting product updates to clients in the room\n    dbStream.on(\"change\", (change) =\u003e {\n      if (change.operationType === \"update\") {\n        socketio.in(change.documentKey._id).emit(\"product-update\", {\n          _id: change.documentKey._id,\n          ...change.updateDescription.updatedFields,\n        });\n      }\n    });\n\nClients can then listen for the `product-update` event and update their UI accordingly.\n\nContributing\n------------\n\nFeel free to contribute to the project by opening issues or submitting pull requests.\n\nLicense\n-------\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdxtaner%2Fe-commerce-backend-nodejs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdxtaner%2Fe-commerce-backend-nodejs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdxtaner%2Fe-commerce-backend-nodejs/lists"}