{"id":18330070,"url":"https://github.com/semklim/expressjs_mongo_api_example","last_synced_at":"2026-04-11T00:08:14.994Z","repository":{"id":203149800,"uuid":"697931226","full_name":"semklim/Expressjs_Mongo_Api_example","owner":"semklim","description":"Website example of Authentication and Registration API","archived":false,"fork":false,"pushed_at":"2024-05-03T11:34:00.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-15T10:31:59.910Z","etag":null,"topics":["api","cors","css","email-sender","express","expressjs","html-css-javascript","html5","javascript","jwt-authentication","mongodb","nodejs","registration","web-authentication","web-register-form"],"latest_commit_sha":null,"homepage":"https://webapi-example.vercel.app","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/semklim.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"publiccode":null,"codemeta":null}},"created_at":"2023-09-28T19:14:09.000Z","updated_at":"2024-05-03T11:34:04.000Z","dependencies_parsed_at":null,"dependency_job_id":"d03ff68f-b03a-42b6-8cf8-3d2f2fc68172","html_url":"https://github.com/semklim/Expressjs_Mongo_Api_example","commit_stats":null,"previous_names":["semklim/expressjs_mongo_api_example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semklim%2FExpressjs_Mongo_Api_example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semklim%2FExpressjs_Mongo_Api_example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semklim%2FExpressjs_Mongo_Api_example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/semklim%2FExpressjs_Mongo_Api_example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/semklim","download_url":"https://codeload.github.com/semklim/Expressjs_Mongo_Api_example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248078902,"owners_count":21044200,"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":["api","cors","css","email-sender","express","expressjs","html-css-javascript","html5","javascript","jwt-authentication","mongodb","nodejs","registration","web-authentication","web-register-form"],"created_at":"2024-11-05T19:20:14.025Z","updated_at":"2025-12-30T23:05:12.898Z","avatar_url":"https://github.com/semklim.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Website example of Authentication and Registration API using CORS, JSON Web Tokens, nodemailer, Express.js and MongoDB\n\nThis README provides a comprehensive guide on how to set up and use the Authentication and Registration API using Express.js and MongoDB. This API allows you to handle user registration, activation, authentication, token refresh, retrieve users' information from the database, and manage email-based activation, as well as handle user logout.\n\n## Prerequisites\n\nBefore you begin, ensure you have the following prerequisites:\n\n- Node.js and npm installed\n- Basic understanding of Express.js and MongoDB\n\n## Getting Started\n\n1. Install dependencies:\n\n```bash\nnpm i\n```\n\n2. Create a `.env` file in the root directory. Look inside the file .env.example for details.\n\n3. Check how to use google smtp server for sending email. Otherwise you will get an error.\n\n[https://support.google.com/a/answer/176600?hl=en](https://support.google.com/a/answer/176600?hl=en)\n[https://support.google.com/a/answer/2956491?sjid=4893799287504753245-EU#sendinglimitsforrelay](https://support.google.com/a/answer/2956491?sjid=4893799287504753245-EU#sendinglimitsforrelay)\n\n## Usage\n\n### User Registration\n\nEndpoint: `POST /api/register`\n\nTo register a new user, send a POST request to the `/api/register` endpoint with the following JSON payload:\n\n```json\n{\n  \"userName\": \"semklim\",\n  \"password\": \"12312\",\n  \"email\": \"semklim@gmail.com\"\n}\n```\n\n### User Activation\n\nEndpoint: `GET /api/activate/:link`\n\nWhen a user clicks the activation link received via email, they will be activate and redirected to the main page of your app.\n\n### User Authentication\n\nEndpoint: `POST /api/login`\n\nTo authenticate a user, send a POST request to the `/api/login` endpoint with the following JSON payload:\n\n```json\n{\n  \"userEmail\": \"semklim@gmail.com\",\n  \"password\": \"200996Ro\"\n}\n```\n\n### Token Refresh\n\nEndpoint: `POST /api/refresh`\n\nTo refresh the access token, send a POST request to the `/api/refresh` endpoint. Make sure to include the `refreshToken` in the cookies of the request.\n\n### User Logout\n\nEndpoint: `POST /api/logout`\n\nTo log out a user, send a POST request to the `/api/logout` endpoint. This should delete the `refreshToken` cookie on the client side.\n\n### Protected Route - Retrieve Users\n\nEndpoint: `GET /api/users`\n\nTo retrieve a list of all users from the database, send a GET request to the `/api/users` endpoint. Ensure that you include the `Authorization` header in your request with the format: `Bearer \u003ctoken\u003e`, where `\u003ctoken\u003e` is the valid access token obtained upon successful login.\n\n### Error Handling\n\n- If registration, activation, authentication, token refresh, or logout fails due to invalid input or other reasons, you will receive an appropriate error response.\n- Ensure to handle errors gracefully on the client-side by checking the response status and the content of the response body.\n\n## Running the Server\n\nStart the Express server by running:\n\n```bash\nnpm start\n```\n\nThe server will run on the port 5000.\n\n## Conclusion\n\nThis API provides a secure and feature-rich way to handle user registration, activation, authentication, token refresh, user information retrieval, email-based activation, and user logout using Express.js and MongoDB. Feel free to extend and customize the API to suit your application's specific requirements.\n\nIf you have any questions or need further assistance, please don't hesitate to reach out.\n\nHappy coding!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemklim%2Fexpressjs_mongo_api_example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsemklim%2Fexpressjs_mongo_api_example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsemklim%2Fexpressjs_mongo_api_example/lists"}