A robust and clean boilerplate/starter project with proper error handling for quickly building RESTful APIs using Node.js, Express, and Sequelize ORM.
steps:
- Clone the repo:
git clone https://github.com/bhavinvirani/node-sequelize-setup.git
cd <project_directory>
- Install the dependencies:
npm install
- Set the environment variables:
cp .env.example .env
PORT=8080
CORS_ORIGIN="*"
NODE_ENV = "development"
# Database (Postgres)
DB_USERNAME = ""
DB_PASSWORD = ""
DB_NAME = ""
DB_HOST = "localhost"
DB_DIALECT = ""
DB_PORT = 5432
# JWT
JWT_SECRET = ""
SALT_ROUND = 5
JWT_EXPIRATION = "1d"
ACCESS_TOKEN_EXPIRATION = "14m"
REFRESH_TOKEN_EXPIRATION = "90d"
PASSWORD_TOKEN_EXPIRATION = "90m"
# Email (NodeMailer)(Ethereal mail)
SMTP_HOST = 'smtp.ethereal.email'
SMTP_PORT = 587
SMTP_USERNAME = ''
SMTP_PASSWORD = ''
SMTP_EMAIL_FROM = ''
# Password reset token
PASSWORD_TOKEN_BYTES = 32
PASSWORD_TOKEN_TYPE = "hex"
PASSWORD_TOKEN_EXPIRATION_DURATION = 600
# Cloudinary
CLOUDINARY_CLOUD_NAME = ""
CLOUDINARY_API_KEY = ""
CLOUDINARY_API_SECRET = ""
npm run dev
project-root/
|--db/
| |--migration
| |--seeder
|--public/
| |--images
| |--logs # logs
|--src/
| |--api/
| |--controllers. # Route Controller
| |--models # Sequelize models
| |--services. # service
| |--config. # project config
| |--middlewares # custom express middlewares
| |--routs. # Express routs
| |--utils. # Utility functions
| |--validations. # Data validation schema
|--app.js. # Express app
|--server.js. # Entry point
List of available routes:
General routes:
GET api/ - get server status
PATCH api/sync - Sync model with database
Auth routes:
POST api/v1/auth/register - register
POST api/v1/auth/login - login
POST api/v1/auth/forgot-password - send reset password email
POST api/v1/auth/reset-password - reset password
POST api/v1/auth/logout - logout
POST api/v1/auth/refresh-tokens - refresh access and refresh tokens
POST api/v1/auth/send-verification-email - send verification email
GET api/v1/auth/verify-email - verify email
User routes:
GET api/v1/user - get all users
GET api/v1/user/:userId - get all users
PUT api/v1/user/:userId - update users
DELETE api/v1/user/:userId - delete user
If you come across any bugs or have suggestions for improvements, we encourage you to contribute to the project. Please follow these guidelines when reporting issues or submitting pull requests:
If you find a bug or unexpected behavior, kindly create a new issue in the Issues section of this repository. When reporting a bug, please provide as much detail as possible, including steps to reproduce the issue, your environment (operating system, browser, etc.), and any error messages you may have encountered.
I welcome contributions! If you have enhancements or bug fixes you'd like to share, please follow these steps:
- Fork the repository and create your branch from
main. - Make your changes and ensure they adhere to the coding standards.
- Test your changes thoroughly.
- Update the README if needed.
- Submit a pull request, clearly describing the changes you've made.
I appreciate your help in improving this project!