Quick Start Project is a Node.js server based on the Express framework and MySQL database.
In this project we define an elegant and intuitive project structure, able to separate the correct responsibilities between the files. Furthermore, the basic functionalities of an Express server are already implemented, to have a ready-to-use project, where the only concern is to implement the API.
- Express Framework for the basis of the application
- Easy configuration environment via .env file
- APIs protection based on Keycloak IAM. (See documentation)
- Prisma as database client ORM. (MySQL was used, but you can easily change database type)
- Custom Exceptions and automatic error handling. (See documentation)
- Custom Logger based on winston and morgan libraries. (See documentation)
- Easily Validations based on express-validator library. (See documentation)
- Secure Real time based on Socket.io library. (See documentation)
- Easily release with Docker. (See documentation)
project
│ .env
│ README.md
├── docker # Files required for creating staging and production docker images
├── docs # Documentation
├── logs # Automatically generated, contains application logs divided into days
├── prisma
│ │ schema.prisma # The schema definition of the Models
│ └── migrations # Contains the migration files
├──src
│ │ app.ts
│ │ environment.ts
│ ├── controllers # The controllers handles all the logic and sending responses with correct codes
│ ├── exceptions # The custom exceptions
│ ├── helpers # Helper functions / classes
│ ├── interfaces # The custom interfaces
│ ├── middlewares # The custom middlewares
│ ├── routes # The API routes maps to the Controllers
│ ├── services # The services contains the database queries and returning objects or throwing errors
│ └── validations # Validations to validate data before being processed by controllers (used in routes)
└── storage # Automatically generated, contains the uploaded files from users
- Copy and rename
.env.example
file to.env
and edit settings (See Keycloak settings documentation) - Run
npm install
command to install dependencies - Run
npx prisma migrate dev
command to initialize the database ornpx prisma generate
command if the database already exists - Run
npm start
ornpm run dev
command to run local server (it restarts each time the code is changed)
NOTE:
- You can run
npm run build
command to build dist server (you need add .env file manually inside /dist directory) - You can run
npx prisma studio
command to open Prisma Studio in the browser (is a visual editor for the data in your database) - import the file
docs/Express Startup Project.postman_collection.json
to Postman to test the API
- Make a version without Keycloak, use jwt
Want to help out? Found a bug? Missing a feature? Post an issue on our issue tracker.
I welcome contributions no matter how small or big!