Skip to content

A boilerplate for building project RESTful APIs using Node.js, Express, and Sequelize

Notifications You must be signed in to change notification settings

devinaacs/express-sequelize-boilerplate

Repository files navigation

Node.js Express Sequelize Boilerplate

PRs Welcome

This is a boilerplate project for a Node.js application using the Express framework and Sequelize ORM. It provides a structured foundation for building scalable and maintainable server-side applications.

✨ Features

  • Express: A minimal and flexible Node.js web application framework.
  • Sequelize: A promise-based Node.js ORM for PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server.
  • PostgreSQL: Using pg as the PostgreSQL client.
  • Environment Configuration: Manage configuration settings using environment variables.
  • dotenv: A zero-dependency module that loads environment variables from a .env file into process.env.
  • jsonwebtoken: For secure JWT token creation and verification.
  • bcryptjs: For hashing and comparing passwords securely.
  • cors: Middleware for enabling Cross-Origin Resource Sharing (CORS).
  • moment-timezone: Timezone support for moment.js.
  • Sequelize CLI: (Development Dependency) Command-line interface for Sequelize.

🛠️ Prerequisites

  • Node.js (>= 16.x)
  • npm (>= 8.x) or yarn (>= 1.x)
  • A SQL database (e.g., PostgreSQL, MySQL, SQLite)

🛠️ Installation Steps:

  1. Clone the repository:
    git clone https://github.com/devinaacs/express-sequelize-boilerplate.git 
    cd express-sequelize-boilerplate
  1. Install dependencies:
    npm install
    # or
    yarn install
  1. Set up environment variables:

Create a .env file in the root of the project based on .env.example file, and add your environment variables. Example:

    NODE_ENV=development
    PORT=3000
    PG_HOST=localhost
    PG_USERNAME=root
    PG_PASSWORD=yourpassword
    PG_DATABASE=yourdatabase

🚀 Running the Application

  1. Run database migrations:
    sequelize db:migrate
  1. Run database seeders:
    sequelize db:seed:all
  1. Start the development server:
    npm run start
    # or
    yarn start

📁 Project Structure

.
├── config
│   └── config.js
├── constants
│   └── exampleConstant.js
├── controllers
│   └── exampleController.js
├── helpers
│   └── exampleHelper.js
├── middlewares
│   └── exampleMiddleware.js
├── migrations
│   └── exampleMigration.js
├── models
│   ├── index.js
│   └── exampleModel.js
├── routes
│   └── exampleRoutes.js
├── seeders
│   └── exampleSeeders.js
├── services
│   └── exampleService.js
├── utils
│   └── exampleUtil.js
├── validators
│   └── exampleValidator.js
├── .env
├── .env.example
├── .gitignore
├── app.js  
├── package.json
└── README.md
  • config: Configuration files for the application and database.
  • constants: Files containing constants used throughout the application.
  • controllers: Route handlers to separate request handling logic.
  • helpers: Utility functions to be used across the application.
  • middlewares: Express middlewares for handling requests.
  • migrations: Sequelize migrations for database schema changes.
  • models: Sequelize models and database schema definitions.
  • routes: Route definitions for the application.
  • seeders: Sequelize seeders for populating the database with initial data.
  • services: Business logic separated from controllers.
  • utils: Utility functions to support the application.
  • validators: Validation logic for request data.

🤝 Contributing

Contributions are welcome! Please create an issue or submit a pull request for any changes.

📜 License

This project is licensed under the MIT License. See the LICENSE file for more details.

You can copy this content into a `README.md` file in your project directory. Adjust any paths, configurations, and examples to fit your specific project setup.

About

A boilerplate for building project RESTful APIs using Node.js, Express, and Sequelize

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published