Skip to content

Commit

Permalink
Merge pull request #11 from techstartucalgary/build/prisma-config
Browse files Browse the repository at this point in the history
Build/prisma config
  • Loading branch information
Axeloooo authored Nov 19, 2023
2 parents dd13e1d + 9995b95 commit a790565
Show file tree
Hide file tree
Showing 23 changed files with 427 additions and 190 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
.env
dist
migrations
110 changes: 35 additions & 75 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

All the code is located in the `backend/src` directory. The backend is written using [Node.js](https://nodejs.org/en/) and [Express](https://expressjs.com/).

### 🏃 Quickstart with Node.js
### 🏃 Quickstart

1. Make sure you have `Node.js` and `NPM` installed on your machine. Click [here](https://nodejs.org/en/) to download and install Node.js. Make sure you install the LTS version. NPM is installed automatically when you install Node.js.

Expand All @@ -22,156 +22,116 @@ npm -v

4. If you see the version number of `Node.js` and `npm` then you are good to go. If not, then try to reinstall `Node.js`.

5. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).
5. Make sure you have `MySQL` installed on your machine. Click [here](https://dev.mysql.com/downloads/mysql/) to download and install MySQL. Make sure you install the latest version.

```bash
git clone git@github.com:techstartucalgary/fashion.git
```

6. `cd` into the `backend` directory.

```bash
cd backend
```

7. Run `npm install --only=production` to install all the dependencies.
6. Open the terminal and run `mysql --version` to check if `MySQL` is installed.

```bash
npm install --only=production
mysql --version
```

8. Run `npm run start` to start the server.
7. If you see the version number of `MySQL` then you are good to go. If not, then try to reinstall `MySQL`.

```bash
npm run start
```
8. Make sure you have `Redis` installed on your machine. Click [here](https://redis.io/download) to download and install Redis. Make sure you install the latest version.

9. Open the browser and go to `http://localhost:8080/` to see the server running.
9. Open the terminal and run `redis-server --version` to check if `Redis` is installed.

```bash
http://localhost:8080/
redis-server --version
```

### 🐳 Quickstart with Docker
10. If you see the version number of `Redis` then you are good to go. If not, then try to reinstall `Redis`.

1. Make sure you have `Docker` installed on your machine. Click [here](https://docs.docker.com/get-docker/) to download and install Docker.

2. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).
11. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

```bash
git clone git@github.com:techstartucalgary/fashion.git
```

3. `cd` into the `backend` directory.
12. `cd` into the `backend` directory.

```bash
cd backend
```

4. Run `docker-compose up` to start the server.
13. Run `npm install --only=production` to install all the dependencies.

```bash
docker-compose -f docker-compose.prod.yml up -d
npm install
```

5. Open the browser and go to `http://localhost:8080/` to see the server running.
14. Run `npm run start` to start the server.

```bash
http://localhost:8080/
```

### ❤️ Health check

To check if the backend is running, open the browser and go to `http://localhost:8080/api/v1/health`. You should see the following message.

```bash
{"status":"healthy"}
npm run start
```

### 🚧 Development Environment

Using Docker (Recommended)

1. Make sure you have `Docker` installed on your machine. Click [here](https://docs.docker.com/get-docker/) to download and install Docker.
1. Make sure you have `Node.js` and `NPM` installed on your machine. Click [here](https://nodejs.org/en/) to download and install Node.js. Make sure you install the LTS version. NPM is installed automatically when you install Node.js.

2. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).
2. Open the terminal and run `node -v` to check if `Node.js` is installed.

```bash
git clone git@github.com:techstartucalgary/fashion.git
node -v
```

3. `cd` into the `backend` directory.
3. In the same terminal run `npm -v` to check if `npm` is installed.

```bash
cd backend
npm -v
```

4. Run `docker-compose up` to start the server.
4. If you see the version number of `Node.js` and `npm` then you are good to go. If not, then try to reinstall `Node.js`.

```bash
docker-compose -f docker-compose.dev.yml up -d
```
5. Make sure you have `MySQL` installed on your machine. Click [here](https://dev.mysql.com/downloads/mysql/) to download and install MySQL. Make sure you install the latest version.

5. Open the browser and go to `http://localhost:8080/` to see the server running.
6. Open the terminal and run `mysql --version` to check if `MySQL` is installed.

```bash
http://localhost:8080/
mysql --version
```

Using Node.js
7. If you see the version number of `MySQL` then you are good to go. If not, then try to reinstall `MySQL`.

1. Make sure you have `Node.js` and `NPM` installed on your machine. Click [here](https://nodejs.org/en/) to download and install Node.js. Make sure you install the LTS version. NPM is installed automatically when you install Node.js.
8. Make sure you have `Redis` installed on your machine. Click [here](https://redis.io/download) to download and install Redis. Make sure you install the latest version.

2. Open the terminal and run `node -v` to check if `Node.js` is installed.
9. Open the terminal and run `redis-server --version` to check if `Redis` is installed.

```bash
node -v
redis-server --version
```

3. In the same terminal run `npm -v` to check if `npm` is installed.
10. If you see the version number of `Redis` then you are good to go. If not, then try to reinstall `Redis`.

```bash
npm -v
```

4. If you see the version number of `Node.js` and `npm` then you are good to go. If not, then try to reinstall `Node.js`.

5. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).
11. Open the terminal and clone this repository using HTTPS or SSH (The example below uses SSH).

```bash
git clone git@github.com:techstartucalgary/fashion.git
```

6. `cd` into the `backend` directory.
12. `cd` into the `backend` directory.

```bash
cd backend
```

7. Run `npm install` to install all the dependencies.
13. Run `npm install` to install all the dependencies.

```bash
npm install
```

8. Run `npm run start` to start the server.
14. Run `npm run start` to start the server.

```bash
npm run dev
```

9. Open the browser and go to `http://localhost:8080/` to see the server running.

```bash
http://localhost:8080/
```

Environment Variables

The environment variables must be located in the `backend/.env` file (If not such file exists, create one). The following environment variables are required to run the server.
15. Run `npx prisma studio` to open Prisma Studio and view the database schema (Optional).

```bash
PORT=<port number>
npx prisma studio
```

### 🧪 Testing
Expand Down
6 changes: 0 additions & 6 deletions backend/.dockerignore

This file was deleted.

11 changes: 0 additions & 11 deletions backend/Dockerfile

This file was deleted.

30 changes: 0 additions & 30 deletions backend/docker-compose.dev.yml

This file was deleted.

23 changes: 0 additions & 23 deletions backend/docker-compose.prod.yml

This file was deleted.

50 changes: 50 additions & 0 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@
"type": "module",
"scripts": {
"build": "npx tsc",
"prestart": "npm run build",
"prestart": "npx prisma migrate deploy && npx prisma generate",
"start": "NODE_ENV=PROD node dist/src/index.js",
"predev": "npx prisma migrate dev --name init && npx prisma generate",
"dev": "NODE_ENV=DEV nodemon -e ts --exec \"npm run build && node dist/src/index.js\"",
"pretest": "npm run build",
"test": "NODE_ENV=TEST mocha dist/test/**/*.test.js"
"pretest": "npx prisma migrate deploy && npx prisma generate",
"test": "NODE_ENV=TEST npm run build && mocha \"dist/test/**/*.test.js\""
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@prisma/client": "^5.6.0",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2"
Expand All @@ -30,6 +32,7 @@
"chai": "^4.3.10",
"mocha": "^10.2.0",
"nodemon": "^3.0.1",
"prisma": "^5.6.0",
"supertest": "^6.3.3",
"typescript": "^5.2.2"
},
Expand Down
Loading

0 comments on commit a790565

Please sign in to comment.