Day 44 of #100DaysOfCode — Adding TS and Zod to Auth Program

Back on Day 40, I built a mini authentication system using Node.js, Express, MongoDB, Mongoose, bcrypt, and JWT. It worked fine, but it was pure JavaScript — no type safety, no runtime validation. ...

By · · 1 min read
Day 44 of #100DaysOfCode — Adding TS and Zod to Auth Program

Source: DEV Community

Back on Day 40, I built a mini authentication system using Node.js, Express, MongoDB, Mongoose, bcrypt, and JWT. It worked fine, but it was pure JavaScript — no type safety, no runtime validation. Today, on Day 44, I decided to refactor the entire thing with TypeScript and Zod. Link to Day 40 Day 40 of #100DayOfCode — Building a Mini Auth System M Saad Ahmad ・ Mar 14 #webdev #programming #javascript #100daysofcode TL;DR Refactored the Mini Auth System with TypeScript and Zod. TypeScript catches type errors at compile time, Zod validates incoming request data at runtime. The best part: z.infer<> generates TypeScript types directly from Zod schemas, so you never define the same shape twice. Key changes: typed Mongoose models with IUser, extended Express's Request for req.user, and replaced blind req.body access with safeParse(). What Changed at a High Level The folder structure stayed mostly the same. The key additions were: Renaming all .js files to .ts Moving everything into a sr