Deploy a Node.js server very quickly with Fastify and TypeORM.
- 📁 dist/
- 📁 node_modules/
- 📂 src/
- 📁 controllers/
- 📁 entities/
- 📂 routes/
- 📄 index.route.ts
- 📂 services/
- 📄 index.service.ts
- 📄 aws.service.ts
- 📄 emailer.service.ts
- 📄 fastify.service.ts
- 📄 firebase.service.ts
- 📄 redis.service.ts
- 📄 typeorm.service.ts
- 📄 index.ts
- 📄 database.sql
- 📄 example.env
- 📄 package.json
- 📄 postman.json
- 📄 README.md
- 📄 tsconfig.json
- 📄 yarn.lock
First of all, install typescript, nodemon and typeorm-model-generator gobally with yarn.
- At the repository root, download the dependencies with yarn:
yarn
-
Rename the file example.env to .env, and edit the environment variables. Some of them are required when using Fastify and TypeORM as
JWT_SECRET
,SERVER_PORT
andDB_
ones. -
Make sure you're running your database service. Using typeorm-model-generator, export your already created database entities to TypeORM TypesScript classes inside src/entities/ folder.
typeorm-model-generator -h <host> -d <database> -p [port] -u <user> -x [password] -e [engine] --relationIds false --noConfig true -o ./src
You can check the options with typeorm-model-generator --help
.
typeorm-model-generator tends to generate some incongruities. Follow the instructions to fix them:
-
Delete ormconfig.json and tsconfig.json created files inside src/ (
typeorm-model-generator
version < 0.4.0). -
Rename .ts entity class files as you want.
-
Add
extends BaseEntity
at the end of each .ts entity class inside src/entities/ folder. -
Check the nullity of some reference attributes of created .ts class entities.
-
Add aditional services at index.ts services array, if necessary.
-
Add aditional *.route.ts files into index.route.ts routes array, if necessary.
-
Run tsc -w at project root directory.
-
Additionally, run nodemon at dist/ directory.
-
Edit src/ TypeScript code with automatic reload!