When starting a Node.js project with TypeScript, structuring your entry files the right way makes your code cleaner
and easier to scale. In this guide, we’ll set up index.ts
and app.ts
step by step, separating server configuration from application
logic. By the end, you’ll have a production-ready server foundation following TypeScript best practices.
Project Structure Overview
- /src → contains all source code
- index.ts → server entry point
- app.ts → app configuration (middlewares, routes)
- routes/ → define your endpoints
- controllers/ → handle request logic
- utils/ or config/ → helper functions, constants
src\index.ts
src\app.ts
src\config\database.ts
src\config\multer.ts
src\middlewares\auth.ts
src\middlewares\fileUpload.ts
src\middlewares\validate.ts
src\routes\auth.route.ts
src\routes\index.route.ts
src\middlewares\validate.ts
src\types\global.d.ts
src\utils\asset.ts
src\utils\jwt.ts
src\utils\response.ts
src\resources\user.resource.ts
src\controllers\auth.controller.ts
src\controllers\user.controller.ts
.env
prisma\schema.prisma
githube code