{"id":24563748,"url":"https://github.com/mildronize/typescript-crash-course-express","last_synced_at":"2025-07-12T04:37:33.578Z","repository":{"id":227507328,"uuid":"771616058","full_name":"mildronize/typescript-crash-course-express","owner":"mildronize","description":"TypeScript Crash Course - Mar 16-18 2024","archived":false,"fork":false,"pushed_at":"2024-03-16T04:18:21.000Z","size":339,"stargazers_count":15,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T12:04:03.926Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mildronize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-13T16:17:38.000Z","updated_at":"2024-08-19T15:58:33.000Z","dependencies_parsed_at":"2024-03-13T18:01:35.334Z","dependency_job_id":null,"html_url":"https://github.com/mildronize/typescript-crash-course-express","commit_stats":null,"previous_names":["mildronize/typescript-crash-course-mar-16-18-2024"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mildronize%2Ftypescript-crash-course-express","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mildronize%2Ftypescript-crash-course-express/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mildronize%2Ftypescript-crash-course-express/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mildronize%2Ftypescript-crash-course-express/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mildronize","download_url":"https://codeload.github.com/mildronize/typescript-crash-course-express/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249771767,"owners_count":21323164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-23T10:15:37.947Z","updated_at":"2025-04-19T19:05:33.572Z","avatar_url":"https://github.com/mildronize.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript Crash Course\n\n## Introduction\n\nRecently, I've been preparing a private course to teach TypeScript as a crash course within the company. I plan to release recorded videos of the course eventually.\n\nThe course will start by writing an Express Node.js application from scratch and then gradually refactor it to make it more DRY (Don't Repeat Yourself) and type-safe.\n\nWithout TypeScript, refactoring can become quite tedious and less enjoyable. I believe this course will provide a great learning experience for those interested in TypeScript.\n\nThe target audience for this course is expected to have a background in .NET C# and/or React, with a rough split of 60/40. We won't spend too much time on Object-Oriented Programming (OOP) concepts, as the audience should already be familiar with them.\n\nThe main goal of the course is to teach how to build type-safe backend APIs, validate requests, and implement a global error handler (eliminating the need for try-catch blocks in controller handlers).\n\nStay tuned, as I'll be sharing portions of the course (although not covering end-to-end type-safety, as that would be too in-depth for this crash course).\n\n## Teaching Checkpoints\n\nYou can check out different branches corresponding to the teaching checkpoints as follows:\n\n1. `backend-starter` - Setting up a TypeScript project with a monorepo structure using Nx.\n2. `backend-phase-1` - Writing a basic Express API for CRUD operations on user data, using a simple JSON file as the database.\n3. `backend-phase-2-global-error-and-response` - Ensuring consistent response models across routes and implementing a global error handler middleware to handle errors and provide consistent error responses.\n4. `backend-phase-3-typed-route` - Validating requests (query, params, and body) using the Zod library to achieve type-safety at compile-time and runtime. A helper function is created to generate type-safe route endpoints.\n\n## Course Outcome\n\nBy the end of the course, your code will be much cleaner because the controllers will handle data validation and provide type-safety when writing controller routes. Additionally, you won't need to handle try-catch blocks for each route separately, and you'll be able to auto-register routes with Express.\n\nExample of writing a controller:\n\n```ts\nexport class UserController extends BaseController {\n  constructor(protected userRepository: UserRepository) {\n    super();\n  }\n\n  /**\n   * Create a new user\n   */\n  create = route\n    .post('/')\n    .body(\n      z.object({\n        username: z.string(),\n        email: z.string().email(),\n        password: z.string(),\n      })\n    )\n    .handler(async ({ body }) =\u003e {\n      await this.userRepository.create(body);\n      return {\n        message: 'User created successfully',\n      };\n    });\n}\n```\n\nExample of registering routes:\n\nYou can register all routes in a controller like this:\n\n```ts\nconst app = express();\napp.use('/users', new Router().registerClassRoutes(userController).instance);\n```\n\n## Nx Manual\n\n### How to create a new project\n\n```bash\nnpm add --global nx@latest\npnpx create-nx-workspace@latest tscc --preset=ts\n```\n\n### How to create a new node application\n\n```bash\nnx add @nx/node\nnx g @nx/node:application api\n```\n\n### How to create a new library\n\n```bash\nnx g @nx/node:lib core\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmildronize%2Ftypescript-crash-course-express","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmildronize%2Ftypescript-crash-course-express","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmildronize%2Ftypescript-crash-course-express/lists"}