Skip to content

Commit a264274

Browse files
committed
final touches
1 parent 2cb1447 commit a264274

6 files changed

+89
-41
lines changed

.env.production

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ NODE_ENV=production
33

44
# Production Database -- set in production
55
DB_TYPE=postgres
6-
DB_HOST=production-db-host
6+
DB_HOST=localhost
77
DB_PORT=5432
8-
DB_USERNAME=secure_username
9-
DB_PASSWORD=secure_password
8+
DB_USERNAME=postgres
9+
DB_PASSWORD=example
1010
DB_NAME=movie_management_prod
1111
DB_SYNCHRONIZE=false
1212
DB_LOGGING=false
1313

1414
# JWT Production settings
15-
JWT_SECRET=production_secret_key -- set in production
15+
JWT_SECRET=5f2308cac6152783a093846d6e82b60c15087376c07d8599161c4ed1f5654247
1616
JWT_EXPIRES_IN=15m

README.md

+79-33
Original file line numberDiff line numberDiff line change
@@ -219,50 +219,96 @@ The application implements several security features to protect user data and pr
219219

220220
### Installation
221221

222-
1. Clone the repository:
223-
```bash
224-
git clone https://github.com/Me-Baran/movie-management-system.git
225-
cd movie-management-system
226-
```
227-
228-
2. Install dependencies:
229-
```bash
230-
npm install
231-
```
232-
233-
3. Set up environment variables:
234-
```bash
235-
cp .env.example .env
236-
# Edit .env with your configuration
237-
```
238-
239-
4. Start the development server:
240-
```bash
241-
npm run start:dev
242-
```
243-
244-
### Environment Variables
245-
246-
The application requires the following environment variables:
222+
1. Clone the repository
223+
```bash
224+
git clone https://github.com/Me-Baran/movie-management-system.git
225+
cd movie-management-system
226+
```
247227

228+
2. Install dependencies
229+
```bash
230+
npm install
248231
```
249-
# Application
250-
PORT=3000
251-
NODE_ENV=development
252232

253-
# Database
233+
3. Configure environment variables
234+
```
235+
# Database Configuration
254236
DB_TYPE=postgres
255237
DB_HOST=localhost
256238
DB_PORT=5432
257239
DB_USERNAME=postgres
258-
DB_PASSWORD=postgres
240+
DB_PASSWORD=your_password
259241
DB_NAME=movie_management
260242
DB_SYNCHRONIZE=true
261-
DB_LOGGING=true
243+
DB_LOGGING=false
262244
263-
# JWT Authentication
264-
JWT_SECRET=your-secret-key-here
245+
# JWT Configuration
246+
JWT_SECRET=your_very_secure_jwt_secret_key
265247
JWT_EXPIRES_IN=1h
248+
249+
# Server Configuration
250+
PORT=3000
251+
```
252+
253+
4. Create the database
254+
Before running the application, make sure to create the PostgreSQL database:
255+
```bash
256+
# Connect to PostgreSQL
257+
psql -U postgres
258+
259+
# Create the database
260+
CREATE DATABASE movie_management;
261+
262+
# Exit psql
263+
\q
264+
```
265+
266+
5. Start the application
267+
```bash
268+
npm run start:dev
269+
```
270+
271+
## Running in Different Environments
272+
273+
The application can run in different environments:
274+
275+
- **Development**:
276+
```bash
277+
# Requires a .env.development file
278+
npm run start:dev
279+
```
280+
281+
- **Production**:
282+
```bash
283+
# Requires a .env.production file
284+
npm run start:prod
285+
```
286+
287+
- **Test**:
288+
```bash
289+
# Requires a .env.test file
290+
npm run test
291+
```
292+
293+
Make sure to create the appropriate database for each environment before running the application. The application will look for the database name specified in your environment configuration.
294+
295+
The API will be available at http://localhost:3000
296+
Swagger documentation will be available at http://localhost:3000/api
297+
298+
## Production Deployment
299+
300+
When running the application in production mode:
301+
302+
1. Create a production database
303+
```bash
304+
# Connect to PostgreSQL
305+
psql -U postgres
306+
307+
# Create the production database
308+
CREATE DATABASE movie_management_prod;
309+
310+
# Exit psql
311+
\q
266312
```
267313

268314
For testing, the app uses SQLite in-memory database by default.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"scripts": {
99
"build": "nest build",
1010
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
11-
"start": "nest start",
11+
"start": "NODE_ENV=production nest start",
1212
"start:dev": "NODE_ENV=development nest start --watch",
1313
"start:debug": "NODE_ENV=development nest start --debug --watch",
1414
"start:prod": "NODE_ENV=production node dist/main",

src/app.module.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import { TicketModule } from './modules/ticket/ticket.module';
1616
// Configuration module
1717
ConfigModule.forRoot({
1818
isGlobal: true,
19-
envFilePath: `.env${process.env.NODE_ENV ? '.' + process.env.NODE_ENV : ''}`
19+
envFilePath: `.env${process.env.NODE_ENV ? '.' + process.env.NODE_ENV : ''}`,
20+
expandVariables: true,
2021
}),
2122

2223
// Database

src/app.service.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ import { Injectable } from '@nestjs/common';
33
@Injectable()
44
export class AppService {
55
getHello(): string {
6-
return 'Hello World!';
6+
return 'Movie Management System';
77
}
88
}

src/main.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as compression from 'compression';
66
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
77

88
async function bootstrap() {
9+
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
910
const logger = new Logger('Bootstrap');
1011
const app = await NestFactory.create(AppModule);
1112

@@ -42,7 +43,7 @@ async function bootstrap() {
4243
// Start the server
4344
const port = process.env.PORT || 3000;
4445
await app.listen(port);
45-
logger.log(`Application listening on port ${port}`)
46+
logger.log(`Application listening on http://localhost:${port} in ${process.env.NODE_ENV} mode`);
4647
}
4748
bootstrap();
4849

0 commit comments

Comments
 (0)