Building an Express Server Using TypeScript

  1. Create a folder called server

  2. type cd server or open the folder in vs code

  3. Execute This Command

     npm init -y
    
  4. Install Typescript

     npm i typescript
     npm install -g typescript
     npm i -D typescript  @types/node
    
  5. Install libraries With Thier Types

     npm i express @types/express
    
  6. npx tsc init

  7. create src and dist folder into server folder

  8. open tsconfig.json
    change rootDir “./” to “./src”
    change outDir “./” to “./dist”

  9. Create Folders Like Middleware, Models, Route And Controller Into Src Folder

  10. Change package.json File Like Below Mentioned:

  11. {
      "name": "server",
      "version": "1.0.0",
      "main": "server.js",
      "scripts": {
        "dev":"tsc -b && node ./dist/server.js"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "description": "",
      "dependencies": {
        "typescript": "^5.7.2"
      }
    }
    
  12. run npm run dev in the terminal

  13. npm i @types/express @types/bcrypt @types/cookie-parser @types/cors

Conclusion

By This U can create your express server in typescript, In we have learn how to setup typescript in our express project or globally and learned to install types of packages used in building express server.