Skip to content

guilhermemntt/fastify-typeorm-boilerplate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastify-typeorm-boilerplate

Deploy a Node.js server very quickly with Fastify and TypeORM.

File structure

  • 📁 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

Run

First of all, install typescript, nodemon and typeorm-model-generator gobally with yarn.

  1. At the repository root, download the dependencies with yarn:
yarn
  1. 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 and DB_ ones.

  2. 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.

  1. Add aditional services at index.ts services array, if necessary.

  2. Add aditional *.route.ts files into index.route.ts routes array, if necessary.

  3. Run tsc -w at project root directory.

  4. Additionally, run nodemon at dist/ directory.

  5. Edit src/ TypeScript code with automatic reload!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published