Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsuyog2/express-sequelize-api
Express Sequelize API repository! This project is a robust and scalable RESTful API built using Express.js and Sequelize. It provides a clean and efficient backend solution for managing data and handling various API requests in a Node.js environment.
https://github.com/jsuyog2/express-sequelize-api
api api-development backend express expressapi expressjs expressjs-api jwt jwt-auth jwt-authentication jwt-token loginapi node nodejs postgresql role-based-access-control sequelize unit-testing
Last synced: 2 days ago
JSON representation
Express Sequelize API repository! This project is a robust and scalable RESTful API built using Express.js and Sequelize. It provides a clean and efficient backend solution for managing data and handling various API requests in a Node.js environment.
- Host: GitHub
- URL: https://github.com/jsuyog2/express-sequelize-api
- Owner: jsuyog2
- License: mit
- Created: 2021-02-01T18:30:55.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-09-12T12:37:36.000Z (2 months ago)
- Last Synced: 2024-09-13T00:01:46.713Z (2 months ago)
- Topics: api, api-development, backend, express, expressapi, expressjs, expressjs-api, jwt, jwt-auth, jwt-authentication, jwt-token, loginapi, node, nodejs, postgresql, role-based-access-control, sequelize, unit-testing
- Language: JavaScript
- Homepage: https://github.com/jsuyog2/express-sequelize-api
- Size: 641 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Express Sequelize API
Welcome to the **Express Sequelize API** repository! This project is a robust and scalable RESTful API built using Express.js and Sequelize. It provides a clean and efficient backend solution for managing data and handling various API requests in a Node.js environment.
## Table of Contents
- [Features](#features)
- [Badges](#badges)
- [Tech Stack](#tech-stack)
- [Installation](#installation)
- [Usage](#usage)
- [Build](#build)
- [Environment Variables](#environment-variables)
- [API Endpoints](#api-endpoints)
- [Testing](#testing)
- [Roadmap](#roadmap)
- [Support](#support)
- [Feedback](#feedback)
- [Contributing](#contributing)
- [FAQ](#faq)
- [Acknowledgements](#acknowledgements)
- [Author](#author)
- [License](#license)## Features
- **RESTful API**: Fully functional REST API endpoints for data management.
- **Sequelize Integration**: Utilizes Sequelize ORM for database management with efficient querying.
- **JWT Authentication**: Secure endpoints with JSON Web Token (JWT) based authentication.
- **Role-Based Access Control**: Manage user permissions with role-based access.
- **Validation Middleware**: Validate incoming requests using express-validator.
- **Logging Middleware**: Request logging for monitoring and debugging.
- **Error Handling**: Comprehensive error handling for robust API performance.
- **Unit Tests**: Includes unit tests for middleware and controller functions to ensure code reliability.## Badges
![Node.js CI](https://github.com/jsuyog2/express-sequelize-api/actions/workflows/node.js.yml/badge.svg)
![License](https://img.shields.io/badge/license-MIT-blue.svg)
![Coverage](https://img.shields.io/codecov/c/github/jsuyog2/express-sequelize-api)
![Version](https://img.shields.io/github/package-json/v/jsuyog2/express-sequelize-api.svg)
![Maintenance](https://img.shields.io/maintenance/yes/2024.svg)
## Tech Stack
- **Backend:** Node.js, Express.js
- **Database:** Sequelize (Supports various databases like PostgreSQL, MySQL, etc.)
- **Authentication:** JWT
- **Testing:** Jest
- **Validation:** express-validator
- **Environment Management:** dotenv## Installation
To get started with this project, follow these steps:
1. **Clone the Repository**
```bash
git clone https://github.com/jsuyog2/express-sequelize-api.git
cd express-sequelize-api
```2. **Install Dependencies**
Ensure you have Node.js and npm installed. Then run:
```bash
npm install
```3. **Set Up Environment Variables**
Create a .env file in the root directory of the project. Configure the environment variables as described in [Environment Variables](#environment-variables).
## Usage
### Run Locally
Start the server
```bash
npm run start
```## Build
To build the project using Webpack, use the following commands:
### Production Build
To create an optimized production build:
```bash
npm run build
```This command will generate the bundled files optimized for production in the `dist` directory.
### Start the Server
After building the project, you can start the server with:
```bash
npm run prod
```This command builds the project (if not already built) and then starts the server using the generated `bundle.js` file in the `dist` directory.
## Environment Variables
To run this project, you need to configure the following environment variables in your `.env` file:
- **`PRODUCTION`**: Set to `true` for production mode or `false` for development mode.
- **`BASE_URL`**: The base URL for the application (e.g., `http://127.0.0.1:3000`).
- **`PORT`**: The port on which the application will run (e.g., `3000`).
- **`CORS_LIST`**: Comma-separated list of allowed origins for CORS (e.g., `http://localhost:4200`).
- **`JWT_SECRET`**: Secret key for signing JWT tokens.
- **`JWT_PUBLICKEY_PATH`**: Path to the public key file for JWT verification.
- **`JWT_PRIVATEKEY_PATH`**: Path to the private key file for JWT signing.
- **`SESSION_SECRET`**: Secret key used for session management.
- **`SEQUELIZE_CONNECT`**: Sequelize database connection string (e.g., `postgres://postgres:1234@localhost/pgtest`).
- **`MAIL_HOST`**: SMTP server host for sending emails.
- **`MAIL_PORT`**: SMTP server port for sending emails (e.g., `465`).
- **`MAIL_USERNAME`**: SMTP server username.
- **`MAIL_PASSWORD`**: SMTP server password.Here’s an example `.env` file with the required variables:
```dotenv
PRODUCTION=false
BASE_URL=http://127.0.0.1:3000
PORT=3000
CORS_LIST=http://localhost:4200JWT_SECRET=api_secret_key
JWT_PUBLICKEY_PATH=./express-sequelize-api/key/public.key
JWT_PRIVATEKEY_PATH=./express-sequelize-api/key/private.keySESSION_SECRET=api_session_secret
SEQUELIZE_CONNECT=postgres://postgres:1234@localhost/pgtest
MAIL_HOST=smtp.example.com
MAIL_PORT=465
[email protected]
MAIL_PASSWORD=your_email_password
```Ensure that you replace the placeholder values with your actual configuration details.
## Generating Keys Using OpenSSL
Now you need to create Private and Public Key to generate a Token.
1. **Generate an RSA private key, of size 2048, and output it to a file named `private.key`:**
```bash
openssl genrsa -out key/private.key 2048
```2. **Extract the public key from the key pair, which can be used in a certificate:**
```bash
openssl rsa -in key/private.key -outform PEM -pubout -out key/public.key
```**Note:** Make sure both `key/private.key` and `key/public.key` are saved in the `key` folder.
## API Endpoints
This section provides an overview of the available API endpoints for the application. For detailed request and response formats, refer to the [Postman Documentation](https://documenter.getpostman.com/view/30249900/2sA3s3Jrw9).
### Authentication
- **Login**
- **Endpoint:** `POST /login`
- **Description:** Authenticates a user and returns a JWT token.
- **Body:**
```json
{
"username": "string",
"password": "string"
}
```
- **Responses:**
- **200 OK:** Success
- **401 Unauthorized:** Invalid credentials- **Signup**
- **Endpoint:** `POST /signup`
- **Description:** Registers a new user.
- **Body:**
```json
{
"username": "string",
"password": "string",
"email": "string"
}
```
- **Responses:**
- **201 Created:** Success
- **400 Bad Request:** Validation errors- **Logout**
- **Endpoint:** `POST /logout`
- **Description:** Logs out the user and invalidates the session.
- **Responses:**
- **200 OK:** Success### User Management
- **Get User Profile**
- **Endpoint:** `GET /user`
- **Description:** Retrieves the authenticated user's profile.
- **Headers:**
- **Authorization:** Bearer token
- **Responses:**
- **200 OK:** Success
- **401 Unauthorized:** Invalid token- **Update User Profile**
- **Endpoint:** `PUT /user`
- **Description:** Updates the authenticated user's profile information.
- **Headers:**
- **Authorization:** Bearer token
- **Body:**
```json
{
"username": "string",
"email": "string"
}
```
- **Responses:**
- **200 OK:** Success
- **400 Bad Request:** Validation errors---
For further details and examples, please refer to the [Postman Collection](https://documenter.getpostman.com/view/30249900/2sA3s3Jrw9).
## Testing
To run the unit tests for the project, use:
```bash
npm test
```This command will execute all the tests defined in the `test` directory.
## Roadmap
The roadmap outlines planned features and improvements for the Express Sequelize API project. We aim to continuously enhance the project based on user feedback and evolving requirements.
### Planned Features
- **Enhanced Security**: Implement advanced security features like rate limiting and IP whitelisting.
- **User Roles and Permissions**: Expand role-based access control with more granular permissions.
- **API Rate Limiting**: Introduce rate limiting to prevent abuse and ensure fair usage.
- **Documentation Improvements**: Enhance API documentation with more detailed examples and usage guidelines.
- **Performance Optimizations**: Optimize query performance and server response times.
- **Internationalization (i18n)**: Add support for multiple languages to accommodate global users.
- **Additional Endpoints**: Add new endpoints based on user needs and project requirements.### Future Improvements
- **Docker Support**: Containerize the application for easier deployment and scaling.
- **GraphQL Integration**: Explore integrating GraphQL for flexible data queries.
- **Automated Deployment**: Set up CI/CD pipelines for automated testing and deployment.
- **Advanced Analytics**: Incorporate analytics for monitoring API usage and performance metrics.
## SupportIf you encounter any issues or need assistance with the Express Sequelize API project, here are some ways you can get support:
- **Documentation**: Check the [Postman Collection](https://documenter.getpostman.com/view/30249900/2sA3s3Jrw9) and [README](#) for detailed information on API endpoints and usage.
- **FAQ**: Review the Frequently Asked Questions (FAQ) section in the documentation for common queries and troubleshooting tips.
- **Community Support**: Join discussions and ask questions on relevant forums or community channels.We appreciate your feedback and are committed to providing timely support to ensure the best experience with the Express Sequelize API project.
## Feedback
We welcome feedback on the Express Sequelize API project. If you have any suggestions, improvements, or issues, please let us know. You can provide feedback by:
1. **Opening an Issue**: Report bugs, request features, or provide suggestions by creating a new issue in the [Issues](https://github.com/jsuyog2/express-sequelize-api/issues) section of this repository.
2. **Submitting a Pull Request**: If you have a solution or improvement, feel free to submit a pull request. Please ensure your changes adhere to the project's guidelines and standards.
3. **Contacting the Author**: You can also directly reach out to the project maintainer, [Suyog Dinesh Jadhav](mailto:[email protected]), with any feedback or questions.Your input helps us improve the project and make it better for everyone!
## Contributing
Contributions are welcome! Please follow these steps:
1. Fork the repository.
2. Create a new branch (`git checkout -b feature/your-feature`).
3. Make your changes and commit (`git commit -am 'Add new feature'`).
4. Push the branch (`git push origin feature/your-feature`).
5. Create a new Pull Request.## FAQ
### 1. **How do I set up the project locally?**
To set up the project locally, follow these steps:
1. **Clone the Repository**
```bash
git clone https://github.com/jsuyog2/express-sequelize-api.git
cd express-sequelize-api
```2. **Install Dependencies**
Ensure you have Node.js and npm installed. Then run:
```bash
npm install
```3. **Set Up Environment Variables**
Create a `.env` file in the root directory and configure the necessary environment variables as described in the [Environment Variables](#environment-variables) section.4. **Start the Server**
```bash
npm start
```### 2. **How do I run the tests?**
To run the unit tests, use:
```bash
npm test
```
This command will execute all tests defined in the `test` directory using Jest.### 3. **What should I do if I encounter a bug?**
If you encounter a bug, follow these steps:
1. **Check Existing Issues**
Look at the [Issues](https://github.com/jsuyog2/express-sequelize-api/issues) on GitHub to see if the problem has already been reported.2. **Report a New Issue**
If your issue is not listed, create a [New Issue](https://github.com/jsuyog2/express-sequelize-api/issues/new) on GitHub. Provide a detailed description of the issue, including steps to reproduce it and any relevant screenshots or error logs.### 4. **How can I contribute to the project?**
Contributions are welcome! To contribute:
1. **Fork the Repository**
```bash
git clone https://github.com/your-username/express-sequelize-api.git
```2. **Create a New Branch**
```bash
git checkout -b feature/your-feature
```3. **Make Your Changes**
Make the necessary changes and commit them:
```bash
git commit -am 'Add new feature'
```4. **Push Your Branch**
```bash
git push origin feature/your-feature
```5. **Create a Pull Request**
Open a [Pull Request](https://github.com/jsuyog2/express-sequelize-api/pulls) on GitHub with a description of your changes.### 5. **Where can I find the API documentation?**
API documentation, including endpoint details and usage examples, can be found in the [Postman Documentation](https://documenter.getpostman.com/view/30249900/2sA3s3Jrw9).
### 6. **How do I configure environment variables?**
Refer to the [Environment Variables](#environment-variables) section for details on configuring environment variables in your `.env` file.
### 7. **Can I use this project in production?**
Yes, but make sure to set the `PRODUCTION` environment variable to `true` and properly configure your production environment settings in the `.env` file.
If you have any other questions or need further assistance, feel free to reach out via [email](mailto:[email protected]).
## Acknowledgements
- **Express.js**: A fast, unopinionated, minimalist web framework for Node.js.
- **Sequelize**: A promise-based Node.js ORM for Postgres, MySQL, MariaDB, SQLite, and Microsoft SQL Server.
- **jsonwebtoken**: A library for signing and verifying JSON Web Tokens.
- **bcryptjs**: A library to hash and compare passwords securely.
- **express-validator**: A set of express.js middlewares for validation.
- **dotenv**: A module to load environment variables from a `.env` file into `process.env`.
- **Jest**: A delightful JavaScript testing framework with a focus on simplicity.## Author
This project is maintained by [Suyog Dinesh Jadhav](mailto:[email protected]).
## License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.