{"id":22688205,"url":"https://github.com/emanuelefavero/typescript-backend-guide","last_synced_at":"2026-04-16T10:32:17.522Z","repository":{"id":69318232,"uuid":"554003142","full_name":"emanuelefavero/typescript-backend-guide","owner":"emanuelefavero","description":"This repo is a syntax guide for using Typescript in the backend","archived":false,"fork":false,"pushed_at":"2024-04-26T18:04:32.000Z","size":85,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-28T12:43:29.548Z","etag":null,"topics":["backend","express","guide","nodejs","typescript"],"latest_commit_sha":null,"homepage":"","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/emanuelefavero.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,"publiccode":null,"codemeta":null}},"created_at":"2022-10-19T05:06:37.000Z","updated_at":"2024-04-26T18:04:35.000Z","dependencies_parsed_at":"2025-02-04T16:44:52.867Z","dependency_job_id":"c3eb0bf6-45d1-4fdd-a6ca-8347b3e00098","html_url":"https://github.com/emanuelefavero/typescript-backend-guide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/emanuelefavero/typescript-backend-guide","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Ftypescript-backend-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Ftypescript-backend-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Ftypescript-backend-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Ftypescript-backend-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/emanuelefavero","download_url":"https://codeload.github.com/emanuelefavero/typescript-backend-guide/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/emanuelefavero%2Ftypescript-backend-guide/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31882084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-16T09:23:21.276Z","status":"ssl_error","status_checked_at":"2026-04-16T09:23:15.028Z","response_time":69,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["backend","express","guide","nodejs","typescript"],"created_at":"2024-12-10T00:13:28.727Z","updated_at":"2026-04-16T10:32:17.500Z","avatar_url":"https://github.com/emanuelefavero.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Typescript Backend GUIDE\n\nThis repo is a guide for using Typescript in the backend\n\n## Configuration\n\n### Install Typescript\n\n```bash\nnpm i -D typescript ts-node @types/node @types/express nodemon concurrently\n```\n\n\u003e TIP: `concurrently` is used to run multiple scripts at the same time\n\n- Also, install `express` if you are going to use it:\n\n  ```bash\n  npm i express\n  ```\n\n### Create tsconfig.json\n\n- Run to create a `tsconfig.json` file:\n\n  ```bash\n  npx tsc --init\n  ```\n\n- `tsconfig.json` example:\n\n  ```json\n  {\n    \"compilerOptions\": {\n      \"module\": \"commonjs\",\n      \"esModuleInterop\": true,\n      \"target\": \"es6\",\n      \"moduleResolution\": \"node\",\n      \"sourceMap\": true,\n      \"outDir\": \"dist\",\n      \"rootDir\": \"src\"\n    },\n    \"lib\": [\"es2015\"]\n  }\n  ```\n\n- `target` : Specify ECMAScript target version: 'es5', 'es6', 'es2016', 'es2020', or 'ESNext'.\n- `module` : Specify module code generation: 'commonjs', 'es6', 'es2020', or 'ESNext'.\n- `outDir` : Redirect output structure to the directory.\n- `rootDir` : Specify the root directory of input files. Use to control the output directory structure with --outDir.\n- `strict` : Enable all strict type-checking options.\n- `moduleResolution` : Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6).\n\n### Create a `src` folder with an `index.ts` file\n\n```bash\nmkdir src\ntouch src/index.ts\n```\n\n### Add scripts to `package.json`\n\n```json\n\"scripts\": {\n    \"start\": \"tsc \u0026\u0026 node dist/index.js\",\n    \"build\": \"tsc\",\n    \"dev\": \"concurrently \\\"tsc -w\\\" \\\"nodemon dist/index.js\\\"\"\n  },\n```\n\n### Run typescript in development\n\n```bash\nnpm run dev\n```\n\n### Run typescript in production\n\n```bash\nnpm start\n```\n\n## Syntax Tips\n\n- Usually when using Typescript we use es6 syntax for imports:\n\n  ```typescript\n  import express from 'express'\n  ```\n\n- Express Request, Response, NextFunction:\n\n  ```typescript\n  import { Request, Response, NextFunction } from 'express'\n\n  app.get('/', (req: Request, res: Response, next: NextFunction) =\u003e {\n    res.send('Hello')\n  })\n  ```\n\n- Declaring .env variables:\n\n  ```typescript\n  const mongoDB = process.env.MONGODB_URI || ‘’\n  const PORT = process.env.PORT ? Number(process.env.PORT) || 3000\n  ```\n\n- Mongoose Schemas:\n\n  ```typescript\n  import { Schema } from 'mongoose'\n\n  interface IUser {\n    name: string\n    avatar?: string\n  }\n\n  const UserSchema = new Schema\u003cIUser\u003e({\n    name: {\n      type: string,\n      required: true,\n    },\n    avatar: String,\n  })\n  ```\n\n- Another approach to declare a schema:\n\n  ```typescript\n  import { Schema, InferSchemaType } from 'mongoose'\n\n  const UserSchema = new Schema({\n    name: {\n      type: string,\n      required: true,\n    },\n    avatar: String,\n  })\n\n  type IUser = InferSchemaType\u003ctypeof UserSchema\u003e\n  ```\n\n- Mongoose id type (NOTE: its better to let the database add the id for you)\n\n  ```typescript\n  import { Type } from 'mongoose'\n  // Inside an Interface:\n  _id: Type.ObjectId\n  ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelefavero%2Ftypescript-backend-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Femanuelefavero%2Ftypescript-backend-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Femanuelefavero%2Ftypescript-backend-guide/lists"}