Skip to content

Repository with project developed in NodeJS NLW 04 of Rocketseat Topics

Notifications You must be signed in to change notification settings

tutods/nlw04-node

Repository files navigation

NodeJS NLW-04

NodeJS ExpressJS TypeScript SQLite VS Code



Commands:

  • yarn dev: Start server in dev. mode;
  • yarn test: Run all Jest tests;

    • Note: in jest.config.ts you need specify where you have tests files, in my case:
    testMatch: [
    	'**/tests/*.tests.ts',
    	'**/tests/*.spec.ts',
    ],

Changes:

  • Use /api in base url for all routes (classe 1 - 22/02/21);
  • Use .env file to set server port (classe 1 - 22/02/21);
    • Note: .env.example contains an example of .env file.
  • Create environment.ts file (in /src/configs) to access data from .env file (classe 1 - 22/02/21);
  • Add Husky Hooks to run Prettier and format code in pre-commit (classe 2 - 23/02/21);
  • Custom structure in src/routes (classe 1 - 22/02/21);
    • Note: I use on file per controller, example: UserController I have users.routes, where users.routes contains all routes related with users.
  • Use .spec.ts for tests files (classe 3 - 24/02/21);
  • Validate if already exists migrations on Jest Tests (classe 3 - 24/02/21);
    • Code:
    try {
    	await connection.runMigrations();
    } catch (error) {
    	console.log('Already have migrations!');
    }
  • Capitalize errors from YUP package (classe 5 - 26/02/21).

Problems with Husky Hooks

If Husky Hook pre-commit not working, try run this command: npx mrm lint-staged

Have interest in:
React