https://github.com/jdizm/node-express-sequelize
A demo node/express API project using sequelize and postgres with schema migrations
https://github.com/jdizm/node-express-sequelize
api docker express node postgresql sequelize sql
Last synced: 2 months ago
JSON representation
A demo node/express API project using sequelize and postgres with schema migrations
- Host: GitHub
- URL: https://github.com/jdizm/node-express-sequelize
- Owner: JDIZM
- Created: 2023-07-02T17:31:36.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T16:35:19.000Z (about 2 years ago)
- Last Synced: 2025-03-28T01:50:49.792Z (about 1 year ago)
- Topics: api, docker, express, node, postgresql, sequelize, sql
- Language: JavaScript
- Homepage:
- Size: 201 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-express-sequelize
- node
- express
- sequelize
- postgresql
- pnpm
- docker
## Installation
### package manager
This project uses pnpm to manage dependencies. Install pnpm with `npm install -g pnpm` and run `pnpm install` to install dependencies.
see https://pnpm.io/installation for more information on pnpm.
### volta
This project uses volta to manage node versions. Install volta and run `volta install` to install the correct node version.
To install volta run the following command in the terminal.
```
curl https://get.volta.sh | bash
```
## Usage
Spin up a local docker container with postgresql db using the following command:
```
docker compose up -d
```
Then we will need to run the migrations and seed the db
### run migrations
- `npx sequelize-cli db:migrate`
- `npx sequelize-cli db:migrate:undo:all`
### seed the db
- `npx sequelize-cli db:seed:all`
### dev server
start the dev server with `npm run dev` this will spin up a docker container with postgresql and run the app in watch mode.
### make a request to fetch all users
make a GET request to http://localhost:3000/users
you can use something like [insomnia](https://insomnia.rest/), [postman](https://www.postman.com/) or [httpie](https://httpie.io/cli) to make the request.
You should see a response like this with a user and it's associated bar model:
```json
{
"users": [
{
"id": "1f63b2ad-4273-4fdd-b6a7-dcadf45a2cbe",
"firstName": "John",
"lastName": "Doe",
"email": "johndoe@example.com",
"createdAt": "2023-07-02T21:38:21.154Z",
"updatedAt": "2023-07-02T21:38:21.154Z",
"Bar": {
"id": 1,
"userId": "1f63b2ad-4273-4fdd-b6a7-dcadf45a2cbe",
"createdAt": "2023-07-02T21:38:21.161Z",
"updatedAt": "2023-07-02T21:38:21.161Z"
}
}
]
}
```
## Build the api with docker
replace the `POSTGRES_HOST` with `host.docker.internal` in the .env file to run the app with docker.
```
POSTGRES_HOST=host.docker.internal
```
### Build the image
`docker build -t node-express-sequelize .`
### Run the image
`docker run -d -p 3000:3000 node-express-sequelize`