This repository provides a base REST API built with Node.js, Express.js, and Sequelize, designed to serve as a solid foundation for quickly creating new, secure, and maintainable APIs.
- Modular and scalable project structure (routes, controllers, services, middlewares, models, etc.)
- Ready-to-use JWT authentication
- Enhanced security (Helmet, CORS, rate limiting, error handling)
- Sequelize ORM with migrations and seeders management
- Access and error logging
- Examples for user, role, and UUID management
- Email sending support (via Mailjet/Nodemailer)
- Deployment-ready (scripts, configuration, example .env)
- Node.js >= 16
- PostgreSQL (or any Sequelize-compatible DBMS)
- npm
-
Clone the repository:
git clone https://github.com/AlexisVedrenne/base-api-express-orm.git cd base-api-express-orm -
Install dependencies (choose one):
With npm:
npm install
Or with yarn:
yarn install
-
Configure your environment variables:
- Copy the file
src/config/.exemple.envto.envand adapt it to your environment.
- Copy the file
-
Initialize the database: With npm:
npm run db:create npm run migrate npm run seed:gen:all
Or with yarn:
yarn db:create yarn migrate yarn seed:gen:all
-
Start the development server: With npm:
npm run dev
Or with yarn:
yarn dev
This project is configured to use pkg to generate standalone executables for both Linux and Windows platforms.
-
Install
pkgglobally if you haven't already:npm install -g pkg
-
Build the executable:
npm run build
or directly with:
pkg . -
The executables will be generated in the
distfolder for:- Windows (
node16-win-x64) - Linux (
node16-linux-x64)
- Windows (
- The packaging configuration is defined in the
package.jsonunder thepkgfield. - All necessary assets and scripts are included for the build.
- You can adjust the targets in
package.jsonif you need other platforms.
base-api-express-orm/
├── src/
│ ├── assets/ # Images, email templates, etc.
│ ├── bin/ # Application entry point
│ ├── boot/ # Initialization (e.g., mailer, axios)
│ ├── config/ # Configurations (auth, DB, mailer, etc.)
│ ├── controllers/ # Endpoint logic
│ ├── middleware/ # Custom middlewares
│ ├── models/ # Sequelize models
│ ├── routes/ # Route definitions
│ └── services/ # Reusable business logic
├── migrations/ # Sequelize migrations
├── seeders/ # Example data
├── config/ # Global config (e.g., config.json)
├── app.js # Main Express configuration
├── package.json
└── README.md
The config/config.json file contains the database connection settings used by Sequelize CLI for migrations and seeders. It defines different environments (development, test, production) and their respective database credentials.
{
"development": {
"username": "your_db_user",
"password": "your_db_password",
"database": "your_db_name",
"host": "127.0.0.1",
"dialect": "postgres"
},
"test": {
"username": "your_db_user",
"password": "your_db_password",
"database": "your_test_db_name",
"host": "127.0.0.1",
"dialect": "postgres"
},
"production": {
"username": "your_db_user",
"password": "your_db_password",
"database": "your_prod_db_name",
"host": "127.0.0.1",
"dialect": "postgres"
}
}- Sequelize CLI uses this file to know how to connect to your database when running commands like
db:migrateordb:seed:all. - You can set different credentials for each environment (development, test, production).
- Make sure to keep your credentials secure and never commit sensitive information in a public repository.
- You can use environment variables in this file for better security. For example, with
process.env.DB_USER(see Sequelize documentation for dynamic config). - If you change your database settings, update this file accordingly.
- Always validate and sanitize user input.
- Never store sensitive information directly in the code.
- Regularly update your dependencies.
- Add your own routes, models, and services as needed.
Contributions are welcome! Feel free to open an issue or a pull request to suggest improvements, fix bugs, or add new features.
This project is open-source under the MIT license.