{"id":25026646,"url":"https://github.com/pasan1/auth-crud-app-node-express-mysql","last_synced_at":"2026-04-07T18:33:19.358Z","repository":{"id":181468021,"uuid":"666820544","full_name":"pasan1/auth-crud-app-node-express-mysql","owner":"pasan1","description":"This is a sample Node.js application that demonstrates a CRUD (Create, Read, Update, Delete) operation with MySQL database. The application includes user authentication and authorization, with two different roles: customer and admin.","archived":false,"fork":false,"pushed_at":"2023-07-15T17:33:18.000Z","size":37,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-03T14:05:18.761Z","etag":null,"topics":["auth","authentication","authorization","bycrypt","crud","expressjs","jwt","mysql","node","nodejs"],"latest_commit_sha":null,"homepage":"","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/pasan1.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}},"created_at":"2023-07-15T17:25:12.000Z","updated_at":"2025-02-14T07:33:29.000Z","dependencies_parsed_at":"2023-07-15T18:53:24.977Z","dependency_job_id":null,"html_url":"https://github.com/pasan1/auth-crud-app-node-express-mysql","commit_stats":null,"previous_names":["pasan1/auth-crud-app-node-express-mysql"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/pasan1/auth-crud-app-node-express-mysql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pasan1%2Fauth-crud-app-node-express-mysql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pasan1%2Fauth-crud-app-node-express-mysql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pasan1%2Fauth-crud-app-node-express-mysql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pasan1%2Fauth-crud-app-node-express-mysql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pasan1","download_url":"https://codeload.github.com/pasan1/auth-crud-app-node-express-mysql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pasan1%2Fauth-crud-app-node-express-mysql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31524525,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["auth","authentication","authorization","bycrypt","crud","expressjs","jwt","mysql","node","nodejs"],"created_at":"2025-02-05T17:48:48.197Z","updated_at":"2026-04-07T18:33:19.311Z","avatar_url":"https://github.com/pasan1.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Node.js, Express.js, and MySQL CRUD Application with Authentication and Authorization\n\nThis is a sample Node.js application that demonstrates a CRUD (Create, Read, Update, Delete) operation with MySQL database. The application includes user authentication and authorization, with two different roles: customer and admin.\n\n## Features\n\n- User registration and login with email and password.\n- Access tokens are used for authentication and authorization.\n- Two user roles: customer and admin.\n- Customers can view products and admin can perform all CRUD operations on products and customers.\n- Admin can also change user roles.\n\n## Folder Structure\n\nThe application follows the following folder structure:\n\n- app\n  - controllers\n    - authController.js\n    - customerController.js\n    - productController.js\n    - userController.js\n  - models\n    - customer.js\n    - product.js\n    - user.js\n  - routes\n    - authRoutes.js\n    - customerRoutes.js\n    - productRoutes.js\n    - userRoutes.js\n  - middlewares\n    - authMiddleware.js\n  - utils\n    - database.js\n    - roles.js\n- config\n  - db.config.js\n- server.js\n\n\n## Requirements\n\nTo run this application, you need the following:\n\n- Node.js and npm installed on your machine.\n- MySQL database set up and running.\n- Environment variables for the access token secret and other sensitive information (you can use a .env file).\n\n## Installation\n\n1. Clone the repository or download the source code.\n\n2. Install the dependencies:\n\n```\nnpm install\n```\n\n\n3. Configure the database connection in `config/db.config.js` file.\n\n4. Set up the environment variables (e.g., ACCESS_TOKEN_SECRET) in a .env file at the root of the project.\n\n## Database Setup\n\n1. Create a MySQL database and configure the connection in `config/db.config.js`.\n\n2. Create the necessary tables and insert dummy data. You can find the SQL queries in the previous section of the README.\n\n## Usage\n\nTo start the application, run the following command:\n\n```\nnpm start\n```\n\n\nThe server will start running on port 3000 by default. You can access the API endpoints using tools like Postman or curl.\n\n## API Endpoints\n\n- **POST /api/auth/register**: Register a new user with email and password.\n- **POST /api/auth/login**: Login a user with email and password and get an access token.\n- **GET /api/auth/profile**: Get the user profile with valid access token.\n\n- **GET /api/customers**: Get all customers (admin only).\n- **POST /api/customers**: Create a new customer (admin only).\n- **PUT /api/customers/:id**: Update a customer by ID (admin only).\n- **DELETE /api/customers/:id**: Delete a customer by ID (admin only).\n\n- **GET /api/products**: Get all products.\n- **POST /api/products**: Create a new product (admin only).\n- **PUT /api/products/:id**: Update a product by ID (admin only).\n- **DELETE /api/products/:id**: Delete a product by ID (admin only).\n\n- **PUT /api/users/:id/role**: Update user role by ID (admin only).\n\n## Contributing\n\nContributions are welcome! If you find any issues or want to add new features, please submit a pull request.\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).\n\n## Contact\n\nIf you want to contact me you can reach me at \u003ca href=\"mailto:contact@pasanabeysekara.com\"\u003econtact@pasanabeysekara.com\u003c/a\u003e.\u003c/br\u003e\nConnect with me on [LinkedIn](https://www.linkedin.com/in/pasanabeysekara/).\u003c/br\u003e\nVisit my [web](https://pasanabeysekara.com).\n\n## Acknowledgements\n\n- [Node.js](https://nodejs.org/)\n- [Express.js](https://expressjs.com/)\n- [MySQL](https://www.mysql.com/)\n- [Sequelize](https://sequelize.org/)\n- [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken)\n- [bcrypt](https://www.npmjs.com/package/bcrypt)\n- [dotenv](https://www.npmjs.com/package/dotenv)\n- [Postman](https://www.postman.com/)\n- [bcrypt](https://www.npmjs.com/package/bcrypt)\n- [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpasan1%2Fauth-crud-app-node-express-mysql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpasan1%2Fauth-crud-app-node-express-mysql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpasan1%2Fauth-crud-app-node-express-mysql/lists"}