Skip to content

Commit d07ce67

Browse files
update docs
1 parent 5addf27 commit d07ce67

5 files changed

Lines changed: 204 additions & 12 deletions

File tree

‎README.md‎

Lines changed: 187 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
Node.js Backend is a comprehensive, production-ready RESTful API built with Express.js, featuring JWT authentication, role-based access control, real-time activity logging, advanced security middleware, and comprehensive monitoring capabilities.
1414

15-
**Repository**: [https://github.com/mrdasdeveloper/nodejs-backend](https://github.com/mrdasdeveloper/nodejs-backend)
15+
**Repository**: [https://github.com/fullstack-open-source/nodejs-backend-with-sql](https://github.com/fullstack-open-source/nodejs-backend-with-sql)
1616

1717
## 📋 Table of Contents
1818

@@ -66,6 +66,86 @@ Node.js Backend is a comprehensive, production-ready RESTful API built with Expr
6666
- **Swagger**: Interactive API documentation with Swagger UI
6767
- **Nginx Reverse Proxy**: Production-ready reverse proxy configuration
6868

69+
### 🗄️ Database Support & Flexibility
70+
71+
This project uses **Prisma ORM**, which provides exceptional database flexibility and support for multiple database systems. While the project is configured for **PostgreSQL** by default, Prisma allows you to easily switch between different databases without changing your application code.
72+
73+
#### Currently Configured Database
74+
75+
- **PostgreSQL 16+**: The default database for this project, providing robust relational database features, JSON support, and advanced querying capabilities.
76+
77+
#### Prisma Supported Databases
78+
79+
Prisma ORM supports **10+ database systems**, giving you the flexibility to choose the best database for your needs:
80+
81+
**Self-hosted Databases:**
82+
- ✅ **PostgreSQL** (9.6 - 17) - Currently configured
83+
- ✅ **MySQL** (5.6, 5.7, 8.0, 8.4)
84+
- ✅ **MariaDB** (10.0+)
85+
- ✅ **SQLite** (All versions)
86+
- ✅ **Microsoft SQL Server** (2017, 2019, 2022)
87+
- ✅ **MongoDB** (4.2+)
88+
- ✅ **CockroachDB** (21.2.4+)
89+
90+
**Managed/Cloud Databases:**
91+
- ✅ **AWS Aurora** (All versions)
92+
- ✅ **AWS Aurora Serverless** (All versions)
93+
- ✅ **Azure SQL** (All versions)
94+
- ✅ **CockroachDB-as-a-Service** (All versions)
95+
- ✅ **MongoDB Atlas** (All versions)
96+
- ✅ **Neon Serverless Postgres** (All versions)
97+
- ✅ **PlanetScale** (All versions)
98+
- ✅ **Cloudflare D1** (Preview)
99+
- ✅ **Aiven** (MySQL & Postgres)
100+
101+
#### Advantages of Using Prisma
102+
103+
1. **Database Agnostic**: Switch between databases by simply changing the `provider` in `schema.prisma`
104+
2. **Type Safety**: Auto-generated TypeScript types based on your database schema
105+
3. **Migration Management**: Built-in migration system for schema versioning
106+
4. **Connection Pooling**: Automatic connection pool management for optimal performance
107+
5. **Query Optimization**: Intelligent query builder that generates optimized SQL
108+
6. **Developer Experience**: Intuitive API with excellent IDE autocomplete support
109+
7. **Multi-Database Support**: Use different databases for different environments (e.g., SQLite for development, PostgreSQL for production)
110+
111+
#### Switching Databases
112+
113+
To switch to a different database, simply update the `datasource` provider in `api/prisma/schema.prisma`:
114+
115+
```prisma
116+
// For PostgreSQL (current)
117+
datasource db {
118+
provider = "postgresql"
119+
url = env("DATABASE_URL")
120+
}
121+
122+
// For MySQL
123+
datasource db {
124+
provider = "mysql"
125+
url = env("DATABASE_URL")
126+
}
127+
128+
// For SQLite
129+
datasource db {
130+
provider = "sqlite"
131+
url = "file:./dev.db"
132+
}
133+
134+
// For MongoDB
135+
datasource db {
136+
provider = "mongodb"
137+
url = env("DATABASE_URL")
138+
}
139+
```
140+
141+
Then run:
142+
```bash
143+
npm run prisma:generate # Regenerate Prisma Client
144+
npm run db:push # Push schema to new database
145+
```
146+
147+
**Note**: Some schema features may vary between databases. Refer to [Prisma Database Documentation](https://www.prisma.io/docs/orm/reference/supported-databases) for database-specific considerations.
148+
69149
## 🏗️ Architecture
70150

71151
### System Architecture
@@ -436,8 +516,8 @@ NodeJs Backend API
436516
#### Step 1: Clone Repository
437517

438518
```bash
439-
git clone https://github.com/mrdasdeveloper/nodejs-backend.git
440-
cd nodejs-backend
519+
git clone https://github.com/fullstack-open-source/nodejs-backend-with-sql.git
520+
cd nodejs-backend-with-sql
441521
```
442522

443523
#### Step 2: Setup Environment
@@ -450,6 +530,38 @@ cp example.env .env
450530
nano .env
451531
```
452532

533+
#### Step 2.5: Setup Google Cloud Storage Credentials (Optional)
534+
535+
If you plan to use file upload features, you need to configure Google Cloud Storage credentials:
536+
537+
```bash
538+
# Navigate to credentials directory
539+
cd api/credentials
540+
541+
# Copy the template credential file
542+
cp "google-backend-master copy.json" google-backend-master.json
543+
544+
# Edit the credential file with your Google Cloud Service Account credentials
545+
nano google-backend-master.json
546+
```
547+
548+
**How to get Google Cloud Service Account credentials:**
549+
550+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
551+
2. Select or create a project
552+
3. Navigate to **IAM & Admin** → **Service Accounts**
553+
4. Create a new service account or select an existing one
554+
5. Click on the service account → **Keys** tab
555+
6. Click **Add Key** → **Create new key** → Choose **JSON** format
556+
7. Download the JSON file
557+
8. Copy the contents of the downloaded JSON file into `api/credentials/google-backend-master.json`
558+
559+
**Important Notes:**
560+
- The template file `google-backend-master copy.json` is provided as a reference
561+
- Your actual credentials file `google-backend-master.json` is ignored by git (for security)
562+
- Make sure your service account has the necessary permissions for Google Cloud Storage
563+
- Update `GOOGLE_STORAGE_BUCKET_NAME` in your `.env` file with your bucket name
564+
453565
#### Step 3: Start Services with Docker Compose
454566

455567
```bash
@@ -545,8 +657,8 @@ sudo apt install docker-compose-plugin -y
545657

546658
```bash
547659
# Clone repository
548-
git clone https://github.com/mrdasdeveloper/nodejs-backend.git
549-
cd nodejs-backend/api
660+
git clone https://github.com/fullstack-open-source/nodejs-backend-with-sql.git
661+
cd nodejs-backend-with-sql/api
550662

551663
# Install dependencies
552664
npm install
@@ -562,6 +674,38 @@ cp ../example.env ../.env
562674
nano ../.env
563675
```
564676

677+
#### Step 3.5: Setup Google Cloud Storage Credentials (Optional)
678+
679+
If you plan to use file upload features, configure Google Cloud Storage credentials:
680+
681+
```bash
682+
# Navigate to credentials directory
683+
cd credentials
684+
685+
# Copy the template credential file
686+
cp "google-backend-master copy.json" google-backend-master.json
687+
688+
# Edit the credential file with your Google Cloud Service Account credentials
689+
nano google-backend-master.json
690+
```
691+
692+
**How to get Google Cloud Service Account credentials:**
693+
694+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
695+
2. Select or create a project
696+
3. Navigate to **IAM & Admin** → **Service Accounts**
697+
4. Create a new service account or select an existing one
698+
5. Click on the service account → **Keys** tab
699+
6. Click **Add Key** → **Create new key** → Choose **JSON** format
700+
7. Download the JSON file
701+
8. Copy the contents of the downloaded JSON file into `api/credentials/google-backend-master.json`
702+
703+
**Important Notes:**
704+
- The template file `google-backend-master copy.json` is provided as a reference
705+
- Your actual credentials file `google-backend-master.json` is ignored by git (for security)
706+
- Make sure your service account has the necessary permissions for Google Cloud Storage
707+
- Update `GOOGLE_STORAGE_BUCKET_NAME` in your `.env` file with your bucket name
708+
565709
#### Step 4: Database Setup (Local PostgreSQL)
566710

567711
```bash
@@ -645,8 +789,8 @@ sudo apt install docker-compose-plugin -y
645789

646790
```bash
647791
# Clone repository
648-
git clone https://github.com/mrdasdeveloper/nodejs-backend.git
649-
cd nodejs-backend
792+
git clone https://github.com/fullstack-open-source/nodejs-backend-with-sql.git
793+
cd nodejs-backend-with-sql
650794

651795
# Create production .env file
652796
cp example.env .env
@@ -662,6 +806,41 @@ nano .env
662806
- Configure production database credentials
663807
- Set strong JWT secret (generate with: `openssl rand -base64 32`)
664808
- Configure production Redis, Sentry, and other services
809+
- Set `GOOGLE_STORAGE_BUCKET_NAME` with your production bucket name
810+
811+
#### Step 2.5: Setup Google Cloud Storage Credentials (Required for File Upload)
812+
813+
For production file uploads, configure Google Cloud Storage credentials:
814+
815+
```bash
816+
# Navigate to credentials directory
817+
cd api/credentials
818+
819+
# Copy the template credential file
820+
cp "google-backend-master copy.json" google-backend-master.json
821+
822+
# Edit the credential file with your production Google Cloud Service Account credentials
823+
nano google-backend-master.json
824+
```
825+
826+
**How to get Google Cloud Service Account credentials:**
827+
828+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
829+
2. Select or create a project
830+
3. Navigate to **IAM & Admin** → **Service Accounts**
831+
4. Create a new service account or select an existing one
832+
5. Click on the service account → **Keys** tab
833+
6. Click **Add Key** → **Create new key** → Choose **JSON** format
834+
7. Download the JSON file
835+
8. Copy the contents of the downloaded JSON file into `api/credentials/google-backend-master.json`
836+
837+
**Production Security Notes:**
838+
- The template file `google-backend-master copy.json` is provided as a reference
839+
- Your actual credentials file `google-backend-master.json` is ignored by git (for security)
840+
- Use a dedicated service account with minimal required permissions
841+
- Enable Cloud Storage API in your Google Cloud project
842+
- Ensure your service account has **Storage Object Admin** or **Storage Admin** role
843+
- Never commit your actual credentials file to version control
665844

666845
#### Step 3: Deploy with Docker (Recommended)
667846

@@ -1056,7 +1235,7 @@ Contributions are welcome! This is an open-source project, and we encourage:
10561235
### 📞 Support
10571236

10581237
For issues, questions, or contributions, please visit:
1059-
- **Repository**: [https://github.com/mrdasdeveloper/nodejs-backend](https://github.com/mrdasdeveloper/nodejs-backend)
1238+
- **Repository**: [https://github.com/fullstack-open-source/nodejs-backend-with-sql](https://github.com/fullstack-open-source/nodejs-backend-with-sql)
10601239
- **Issues**: Open an issue on GitHub
10611240

10621241
---
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"type": "service_account",
3+
"project_id": "xxxxxxxxxxx",
4+
"private_key_id": "xyxyxyxyyxyxyxyxyxyxyxyyxyxyxy",
5+
"private_key": "xyxyyxyxyxyxyxyyxyx",
6+
"client_email": "master@xxxxxxxxxxx.iam.gserviceaccount.com",
7+
"client_id": "xyxyxyxyxyxyxyxyxyxyxyxyxyxyxyxy",
8+
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
9+
"token_uri": "https://oauth2.googleapis.com/token",
10+
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
11+
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/master%40xxxxxxxxxxx.iam.gserviceaccount.com",
12+
"universe_domain": "googleapis.com"
13+
}

‎api/package.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
"backend",
3535
"nodejs"
3636
],
37-
"author": "",
38-
"license": "ISC",
37+
"author": "MR DAS - FULL STACK DEVELOPER",
38+
"license": "MIT",
3939
"dependencies": {
4040
"@google-cloud/storage": "^7.7.0",
4141
"@prisma/adapter-pg": "^7.0.0",

‎api/postman/collections/50285861-11918d16-52fa-486e-ab9d-9fa5f9e8be25.json‎

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

‎example.env‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ MODE=prod/v1
99
API_MODE=development
1010
API_VERSION=1.0.0
1111
NODE_ENV=development
12-
DEBUG_MODE=false
12+
DEBUG_MODE=true
1313

1414
# ==============================================================================
1515
# Application Service Ports Configuration

0 commit comments

Comments
 (0)