An open API service indexing awesome lists of open source software.

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

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"
}
...
```