You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Follow these steps to get started with the ScholarX backend:
29
32
30
33
1. Clone this repository to your local machine:
@@ -39,13 +42,13 @@ Follow these steps to get started with the ScholarX backend:
39
42
npm install
40
43
```
41
44
42
-
3. Copy the `.env` file:
45
+
3. Copy `.env.example` file as `.env`:
43
46
44
47
```bash
45
-
cp .env.example .env
48
+
cp .env.example .env#For Linux and macos
46
49
```
47
50
48
-
4. Replace the environment variables in the newly created `.env` file with your configuration.
51
+
4. Replace the environment variables in the newly created `.env` file with your configurations.
49
52
50
53
5. Start the server:
51
54
@@ -61,115 +64,28 @@ Follow these steps to get started with the ScholarX backend:
61
64
62
65
7. Open your web browser and navigate to `http://localhost:${server_port}` to access the running server.
63
66
64
-
## Docker Setup
65
-
66
-
If you prefer to use Docker for development, follow these steps:
67
-
68
-
1. Ensure Docker and Docker Compose are installed on your machine. You can download them from here https://www.docker.com/products/docker-desktop/.
69
-
70
-
2. Build the Docker images:
71
-
72
-
`docker-compose build`
73
-
74
-
3. Start the Docker containers:
75
-
76
-
`docker-compose up`
77
-
78
-
4. The application and its services are now running in Docker containers. You can access the application at `http://localhost:${SERVER_PORT}`, where `SERVER_PORT` is the port number specified in your `.env` file.
79
-
80
-
5. To stop the Docker containers, use the following commnd:
81
-
82
-
`docker-compose down`
83
-
84
-
Please note that the Docker Compose setup assumes that you have a `.env` file in your project root. You can create one by copying the `.env.example` file:
85
-
86
-
`cp .env.example .env`
87
-
88
-
Then, replace the environment variables in the newly created `.env` file with your configuration.
89
-
90
-
The environment directive sets environment variables inside the Docker container. These variables are used to configure the PostgreSQL server. The values for `${DB_USER}`, `${DB_PASSWORD}`, and `${DB_NAME}` should be specified in your .env file.
91
-
92
-
Remember to replace `${SERVER_PORT}` with the actual port number if it's a fixed value. If it's specified in the `.env` file, you can leave it as is.
93
-
94
-
In the `docker-compose.yml` file, we also have a `db` service for the PostgreSQL database:
67
+
Docker Setup (optional)
68
+
-------------------------------------
95
69
96
-
```dockercompose
97
-
db:
98
-
image: postgres:15
99
-
ports:
100
-
- "5432:5432"
101
-
environment:
102
-
- POSTGRES_USER=${DB_USER}
103
-
- POSTGRES_PASSWORD=${DB_PASSWORD}
104
-
- POSTGRES_DB=${DB_NAME}
105
-
```
106
-
107
-
This service uses the official postgres:15 Docker image. The ports directive maps port 5432 inside the Docker container to port 5432 on your host machine, allowing you to connect to the PostgreSQL server at `localhost:5432`.
108
-
109
-
Now, you can connect to the PostgreSQL server running inside the Docker container using a database client. Use `localhost:5432` as the server address, and the `${DB_USER}`, `${DB_PASSWORD}`, and `${DB_NAME}` values from your `.env` file for the username, password, and database name, respectively.
110
-
111
-
### Note
70
+
Alternatively you can use Docker to run ScholarX. Follow these setps:
112
71
113
-
If you have a local PostgreSQL server running on port 5432, you will need to stop it before starting the Docker container, or change the port mapping to avoid a conflict.
72
+
1. Ensure you have Docker and Docker Compose installed on you machine.
114
73
115
-
Remember to replace `${SERVER_PORT}` with the actual port number if it's a fixed value. If it's specified in the `.env` file, you can leave it as is.
116
-
117
-
---
118
-
119
-
#### Code Quality
120
-
121
-
We strive to maintain a high code quality. You can check for linting issues by running:
74
+
2. Build and run the Docker containers.
122
75
123
76
```bash
124
-
npm run lint
77
+
docker compose up --build
125
78
```
79
+
3. The application will be available at `http://localhost:${server_port}`.
126
80
127
-
And to automatically format the code, use:
81
+
4. To stop the containers, run:
128
82
129
83
```bash
130
-
npm run format
84
+
docker compose down
131
85
```
132
86
133
-
## Project Structure
134
-
135
-
Here's an overview of the project structure:
136
-
137
-
```
138
-
scholarx-backend/
139
-
├── src/
140
-
│ ├── controllers/
141
-
│ │ └── index.ts
142
-
│ ├── middleware/
143
-
│ │ └── index.ts
144
-
│ ├── routes/
145
-
│ │ └── index.ts
146
-
│ ├── services/
147
-
│ │ └── auth.service.ts
148
-
│ ├── entities/
149
-
│ │ └── profile.entity.ts
150
-
│ ├── index.ts
151
-
│ └── types.ts
152
-
├── .env.example
153
-
├── .gitignore
154
-
├── package.json
155
-
├── tsconfig.json
156
-
└── README.md
157
-
```
158
-
159
-
-`src/controllers/`: Contains the controller classes that handle incoming requests.
160
-
-`src/middleware/`: Contains the middleware functions used to modify requests and responses.
161
-
-`src/routes/`: Contains the route definitions for the application.
162
-
-`src/services/`: Contains the service definitions for the application.
163
-
-`src/entities/`: Contains the entity models for the application.
164
-
-`src/index.ts`: Creates and configures the Express application and starts the server.
165
-
-`src/types.ts`: Defines custom types for the application.
166
-
-`.env.example`: An example configuration file for environment variables.
167
-
-`.gitignore`: A list of files and directories to be ignored by Git.
168
-
-`package.json`: Contains information about the project and its dependencies.
169
-
-`tsconfig.json`: Configuration file for the TypeScript compiler.
170
-
171
-
Database Configuration and Migration
172
-
------------------------------------
87
+
Database Configuration and Migrations
88
+
-------------------------------------
173
89
174
90
### Setting up the Database
175
91
@@ -180,8 +96,6 @@ Database Configuration and Migration
180
96
```bash
181
97
CREATE DATABASE scholarx;
182
98
```
183
-
184
-
185
99
3. Update your `.env` file with your database configuration:
186
100
187
101
```bash
@@ -191,48 +105,21 @@ Database Configuration and Migration
191
105
DB_PASSWORD=your_db_password
192
106
DB_NAME=scholarx
193
107
```
108
+
4. Synchronize the database schema:
194
109
195
-
### Running Migrations and Seeding the Database
196
-
197
-
#### Migration Commands
198
-
199
-
1. **Generate a new migration**:
200
-
201
-
202
110
```bash
203
-
npm run migration:generate -- -n MigrationName
204
-
```
205
-
206
-
This command generates a new migration file with the specified name.
207
-
208
-
2. **Run migrations**:
209
-
210
-
211
-
```bash
212
-
npm run migration:run
213
-
```
214
-
215
-
This command runs all pending migrations.
216
-
217
-
3. **Synchronize the database schema**:
218
-
219
-
220
-
```bash
221
111
npm run sync:db
222
112
```
113
+
This command synchronizes your database schema with the current state of the entities on your project.
223
114
224
-
This command synchronizes your database schema with the current state of your entities.
225
-
226
-
4. **Seed the database**:
115
+
4. Seed the database
227
116
228
-
229
117
```bash
230
118
npm run seed
231
119
```
232
-
233
120
This command builds the project and runs the database seeding script located in`dist/src/scripts/seed-db.js`.
234
121
235
-
### Example Migration and Seeding Commands
122
+
### Example Migration Commands
236
123
237
124
- To generate a new migration named `AddUserTable`:
238
125
@@ -248,18 +135,15 @@ Database Configuration and Migration
248
135
npm run migration:run
249
136
```
250
137
251
-
- To synchronize the database schema:
252
-
253
-
```bash
254
-
npm run sync:db
255
-
```
138
+
## Setting up SMTP
256
139
257
-
- To seed the database:
140
+
To enable Email functionality in this project, follow these steps:
258
141
259
-
260
-
```bash
261
-
npm run seed
262
-
```
142
+
1. Go to your Google Account. (Make sure to enable 2-step verification)
143
+
2. Go to App Passwords section.
144
+
3. Provide the app name as "scholarx" and click create.
145
+
4. Copy the given password and paste it without spaces forSMTP_PASSWORD propertyin .env file.
146
+
5. Enter your email forSMTP_EMAIL propertyin .env file.
263
147
264
148
## Setting up Google Authentication
265
149
@@ -367,10 +251,40 @@ We appreciate your interest in ScholarX. Happy contributing! If you have any que
367
251
368
252
8. Verify it from your account.
369
253
370
-
## Create dummy data
254
+
## Project Structure
371
255
372
-
1. Run the seeding script:
256
+
Here's an overview of the project structure:
373
257
374
-
```bash
375
-
npm run seed
376
-
```
258
+
```
259
+
scholarx-backend/
260
+
├── src/
261
+
│ ├── controllers/
262
+
│ │ └── index.ts
263
+
│ ├── middleware/
264
+
│ │ └── index.ts
265
+
│ ├── routes/
266
+
│ │ └── index.ts
267
+
│ ├── services/
268
+
│ │ └── auth.service.ts
269
+
│ ├── entities/
270
+
│ │ └── profile.entity.ts
271
+
│ ├── index.ts
272
+
│ └── types.ts
273
+
├── .env.example
274
+
├── .gitignore
275
+
├── package.json
276
+
├── tsconfig.json
277
+
└── README.md
278
+
```
279
+
280
+
- `src/controllers/`: Contains the controller classes that handle incoming requests.
281
+
- `src/middleware/`: Contains the middleware functions used to modify requests and responses.
282
+
- `src/routes/`: Contains the route definitions for the application.
283
+
- `src/services/`: Contains the service definitions for the application.
284
+
- `src/entities/`: Contains the entity models for the application.
285
+
- `src/index.ts`: Creates and configures the Express application and starts the server.
286
+
- `src/types.ts`: Defines custom types for the application.
287
+
- `.env.example`: An example configuration file for environment variables.
288
+
- `.gitignore`: A list of files and directories to be ignored by Git.
289
+
- `package.json`: Contains information about the project and its dependencies.
290
+
- `tsconfig.json`: Configuration file for the TypeScript compiler.
0 commit comments