Skip to content

Repository following course "API Restful Javascript com Node.js, Typescript, TypeORM"

Notifications You must be signed in to change notification settings

tutods/api-ts-typeorm

Repository files navigation

API Restful with TypeScript and TypeORM

📚 Course I follow:

In pt-BR 🇧🇷
Udemy

📃 Technologies

TypeScript NodeJS Redis JWT

🧰 Tools

VS Code

📀 Database

To this project the database used is PostgreSQL in Docker container.

PostgreSQL Docker

⌨️ Commands

  • yarn format or npm run format: run Prettier to format all code (using settings defined in .prettierrc file);
  • yarn dev or npm run dev: run the localhost server;
  • yarn lint or npm run lint: to run the ESLint in your terminal;
  • yarn lint:fix or npm run lint:fix: to run the ESLint and fix the issues;
  • yarn typeorm or npm run typeorm: to run the TypeORM to run or create migrations (for example).

📄 Changes

I have some changes in my project, like:

  • I use Joi to validation fields in requests (body, params or query), and create 3 middlewares:
    • to validate fields in body (req.body);
    • to validate params (req.params);
    • to validate query params (req.query).
  • Create most of the interfaces in src/interfaces folder, and start all files with I (to represent the interface);
  • Use .env file to storage environment variables;
  • Create the src/config/environment.ts file to export objects with .env variables;
  • Create class JoiError to format the errors from Joi validation;
  • Create enum (in src/enums/ and starts with E to represent the enum) to storage the most strings texts to Joi validations;
  • Create middlewares to Joi Validation (shared/middlewares/joiValidation.ts);
  • I don't create configs to AWS S3;
  • Use rimraf package to delete dist/ folder before Babel create build;
  • I don't create the JEST tests, I leave that to ToDo work.

📄 Notes

  • To run production mode (yarn start - files in dist/ folder) you need change the ormconfig.json to:

    {
    	"type": "postgres",
    	"host": "localhost",
    	"port": "5432",
    	"username": "user",
    	"password": "password",
    	"database": "database",
    	"synchronize": true,
    	"entities": ["dist/modules/**/typeorm/entities/*.js"],
    	"migrations": ["dist/shared/typeorm/migrations/*.js"],
    	"cli": {
    		"entitiesDir": "dist/modules /**/typeorm/entities",
    		"migrationsDir": "./dist/shared/typeorm/migrations"
    	}
    }

📜 ToDo:

  1. Swagger Documentation
  2. Wiki in GitHub
  3. Use JEST tests

🔗 Other Links

About

Repository following course "API Restful Javascript com Node.js, Typescript, TypeORM"

Topics

Resources

Stars

Watchers

Forks