This is a backend scaffolding project built with Express.js, TypeScript, Sequelize ORM, and MySQL database. It includes CRUD operations, one-to-many and examples of updating one model with more models.
users-server
├── README.md
├── package.json
├── .sequelizerc
├── src
│ ├── config
│ │ └── sequelize.config.ts
│ ├── controllers
│ │ ├── post.controller.ts
│ │ └── user.controller.ts
│ ├── models
│ │ ├── index.ts
│ │ ├── post.model.ts
│ │ └── user.model.ts
│ ├── routes
│ │ ├── index.ts
│ │ ├── post.routes.ts
│ │ └── user.routes.ts
│ └── index.ts
└── tsconfig.json
- Clone the repository:
git clone https://github.com/brandonjcg/users-server
- Install dependencies:
yarn
- Add a
.env
file with the following variables:
DB_NAME=users
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=password
DB_PORT=3306
DB_SYNC=false|true
- Create a MySQL database named
users
- Run the project:
yarn dev
(oryarn start
for production)
The project includes two models: User
and Post
. The User
model has a one-to-many relationship with the Post
model, and the Post
model has a many-to-many relationship with itself.
The project includes the following routes:
GET /users
: Get all usersGET /users/:id
: Get a user by idPOST /users
: Create a new userPUT /users/:id
: Update a user by idDELETE /users/:id
: Delete a user by idGET /posts
: Get all postsGET /posts/:id
: Get a post by idPOST /posts
: Create a new postPUT /posts/:id
: Update a post by idDELETE /posts/:id
: Delete a post by id
The project includes seeders for the Roles
. To run the seeders, run the following command:
npx tsc -p . && npx sequelize-cli db:seed:all --url 'mysql://user:password@localhost/database'
This project is licensed under the MIT License. See the LICENSE
file for details.
- Brandon Castillo - Software developer 👨🏽💻