https://github.com/alvinmdj/jbl-ecomm-api
https://github.com/alvinmdj/jbl-ecomm-api
fastify jest postgresql typescript
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/alvinmdj/jbl-ecomm-api
- Owner: alvinmdj
- Created: 2025-02-06T15:50:46.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-25T04:16:18.000Z (about 1 year ago)
- Last Synced: 2025-04-03T13:21:20.645Z (about 1 year ago)
- Topics: fastify, jest, postgresql, typescript
- Language: TypeScript
- Homepage:
- Size: 176 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ecomm API
## Getting started
- install dependencies
```sh
npm install
```
- create & fill .env
```sh
# fill .env with .env.example
cp .env.example .env
```
- run postgresql (using docker)
```sh
# build & migrate init.sql
docker-compose up --build
# run detached mode
docker-compose up -d
# verify migration
docker exec -it db-postgres psql -U postgres -d jbl_ecomm_db -c "\dt"
```
- run app (watch)
```sh
npm run dev
# server listening on http://localhost:4000
```
- run tests
```sh
npm run test
```
## Personal notes
Initialize git:
```sh
git init
```
Initialize npm:
```sh
npm init -y
```
Initialize tsconfig:
```sh
npx tsc --init
```
Clean up docker (db):
```sh
docker-compose down -v
```
Setup test with jest & typescript ([jest](https://jestjs.io/docs/getting-started#via-ts-jest), [ts-jest](https://kulshekhar.github.io/ts-jest/docs/getting-started/installation)):
```sh
# install dependencies
npm install --save-dev jest typescript ts-jest @types/jest
# initialize jest config with ts-jest
npx ts-jest config:init
# path mapping from tsconfig to jest config
# https://kulshekhar.github.io/ts-jest/docs/getting-started/paths-mapping
# tsconfig.json (if paths configured like this)
...
"paths": { "@/*": ["./src/*"] },
...
# jest.config.js (add config based on tsconfig paths)
...
moduleNameMapper: {
"^@/(.*)$": "/src/$1",
},
...
# add jest test script to package.json
...
"scripts": {
"test": "jest --watch"
}
...
```