Skip to content

Commit 70bb418

Browse files
authored
.
1 parent 69995cf commit 70bb418

File tree

1 file changed

+113
-1
lines changed

1 file changed

+113
-1
lines changed

README.md

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This script installs Node, Express, TypeScript, ESLint, and Prettier automatical
1313
- [Installation](#installation) ⚙️
1414
- [Scripts](#scripts) 📜
1515
- [Project Structure](#project-structure) 🏗️
16+
- [Database Configuration](#database-configuration) 🗄️
1617
- [Configuration](#configuration) 🔧
1718
- [Contributions](#contributions) 💡
1819
- [Contact](#contact) 📬
@@ -134,6 +135,59 @@ Several scripts have been configured in the package.json file in this project to
134135
- .env: Environment variables.
135136
- .gitignore: gitignore configuration file.
136137

138+
<a name="database-configuration"></a>
139+
## **Database Configuration** 🗄️
140+
During the execution of the script, you will be prompted to choose the database configuration. Here are the available options:
141+
- PostgreSQL with Sequelize
142+
- PostgreSQL with TypeORM
143+
- MySQL with Sequelize
144+
- MongoDB with Mongoose
145+
- No database engine
146+
Depending on your choice, the corresponding dependencies will be installed, and the necessary environment variables will be configured.
147+
- Configuration Example
148+
If you choose PostgreSQL with Sequelize, the pg and sequelize dependencies will be installed, and the following configuration will be added to your .env file:
149+
```makefile
150+
#PostgreSQL Configuration
151+
DB_HOST=localhost
152+
DB_PORT=5432
153+
DB_NAME=your_database
154+
DB_USER=your_username
155+
DB_PASSWORD=your_password
156+
```
157+
For MongoDB with Mongoose, the added configuration will be:
158+
```bash
159+
# MongoDB Configuration
160+
MONGO_URI=mongodb://localhost:27017/your_database
161+
```
162+
For PostgreSQL with TypeORM, in addition to installing the dependencies, the tsconfig.json file will be updated, and the src/config/data-source.ts file will be created with the basic TypeORM configuration:
163+
164+
`src/config/data-source.ts`
165+
```typescrypt
166+
import { DataSource } from "typeorm";
167+
168+
export const AppDataSource = new DataSource({
169+
type: "postgres",
170+
host: process.env.DB_HOST,
171+
port: Number(process.env.DB_PORT),
172+
username: process.env.DB_USER,
173+
password: process.env.DB_PASSWORD,
174+
database: process.env.DB_NAME,
175+
synchronize: true,
176+
logging: false,
177+
entities: ["src/entity/**/*.ts"],
178+
migrations: ["src/migration/**/*.ts"],
179+
subscribers: ["src/subscriber/**/*.ts"],
180+
});
181+
182+
AppDataSource.initialize()
183+
.then(() => {
184+
console.log("Data Source has been initialized!");
185+
})
186+
.catch((err) => {
187+
console.error("Error during Data Source initialization:", err);
188+
});
189+
```
190+
137191
<a name="configuration"></a>
138192
## **Configuration ** 🔧
139193

@@ -254,6 +308,7 @@ Este script instala Node, Express, TypeScript, ESLint y Prettier automáticament
254308
- [Instalación](#instalacion) ⚙️
255309
- [Scripts](#scripts) 📜
256310
- [Estructura del Proyecto](#estructura-del-proyecto) 🏗️
311+
- [Configuración de Base de Datos](#configuracion-de-base-de-datos) 🗄️
257312
- [Configuración](#configuración) 🔧
258313
- [Contribuciones](#contribuciones) 💡
259314
- [Contacto](#contacto) 📬
@@ -376,6 +431,63 @@ En este proyecto se han configurado varios scripts en el archivo package.json pa
376431
- .env: Variables de entorno.
377432
- .gitignore: Archivo de configuración de gitignore.
378433

434+
<a name="configuracion-de-base-de-datos"></a>
435+
## **Configuración de Bases de Datos** 🗄️
436+
437+
Durante la ejecución del script, se te pedirá que elijas la configuración de base de datos. Aquí tienes las opciones disponibles:
438+
439+
- PostgreSQL con Sequelize
440+
- PostgreSQL con TypeORM
441+
- MySQL con Sequelize
442+
- MongoDB con Mongoose
443+
- Sin motor de base de datos
444+
445+
Dependiendo de tu elección, se instalarán las dependencias correspondientes y se configurarán las variables de entorno necesarias.
446+
447+
- _Ejemplo de Configuración_
448+
Si eliges PostgreSQL con Sequelize, las dependencias pg y sequelize se instalarán, y se añadirá la siguiente configuración a tu archivo .env:
449+
```makefile
450+
#PostgreSQL Configuration
451+
DB_HOST=localhost
452+
DB_PORT=5432
453+
DB_NAME=your_database
454+
DB_USER=your_username
455+
DB_PASSWORD=your_password
456+
```
457+
Para MongoDB con Mongoose, la configuración añadida será:
458+
```bash
459+
# MongoDB Configuration
460+
MONGO_URI=mongodb://localhost:27017/your_database
461+
```
462+
Para PostgreSQL con TypeORM, además de instalar las dependencias, se actualizará el archivo tsconfig.json y se creará el archivo src/config/data-source.ts con la configuración básica de TypeORM:
463+
464+
`src/config/data-source.ts`
465+
```typescript
466+
import { DataSource } from "typeorm";
467+
468+
export const AppDataSource = new DataSource({
469+
type: "postgres",
470+
host: process.env.DB_HOST,
471+
port: Number(process.env.DB_PORT),
472+
username: process.env.DB_USER,
473+
password: process.env.DB_PASSWORD,
474+
database: process.env.DB_NAME,
475+
synchronize: true,
476+
logging: false,
477+
entities: ["src/entity/**/*.ts"],
478+
migrations: ["src/migration/**/*.ts"],
479+
subscribers: ["src/subscriber/**/*.ts"],
480+
});
481+
482+
AppDataSource.initialize()
483+
.then(() => {
484+
console.log("Data Source has been initialized!");
485+
})
486+
.catch((err) => {
487+
console.error("Error during Data Source initialization:", err);
488+
});
489+
```
490+
379491
<a name="configuracion"></a>
380492
## **Configuración** 🔧
381493

@@ -479,7 +591,7 @@ Estamos listos para escuchar tus ideas y explorar cómo podemos trabajar juntos
479591

480592

481593
- **Synergy2Devs**
482-
- <a href="mailto:synergy2devs@gmail.com">Escríbenos un email 📧</a>
594+
- <a href="mailto:info@synergy2devs.com">Escríbenos un email 📧</a>
483595
- [Nuestro GitHub](https://github.com/Synergy2Devs)
484596

485597
- **Marcelo Robin**

0 commit comments

Comments
 (0)