Express JS with TypeScript - Setup, Examples, Testing

Поділитися
Вставка
  • Опубліковано 18 січ 2025

КОМЕНТАРІ • 87

  • @kncsmooth8737
    @kncsmooth8737 10 місяців тому +15

    Your clear explanations, detailed examples, and thorough coverage made it a breeze to follow along and understand. I truly appreciate the effort you put into creating such valuable content. Looking forward to more tutorials from you in the future! Keep up the fantastic work!

    • @ansonthedev
      @ansonthedev  10 місяців тому

      Thanks a lot! I do try my best when making vids like these, so to hear stuff like this is very much appreciated. :)

  • @naddulidaniel2630
    @naddulidaniel2630 10 місяців тому +8

    I have been waiting for this tutorial. Here we are. Thank you very much.

  • @sidpd
    @sidpd Місяць тому

    Man, I really appreciate the work you're doing! The content you're creating is incredible, especially with how you dive into the finer details. Like, there's no good video on UA-cam covering annotations and TypeScript setup with Express, and you explain even the smallest things-like when to use `npx` and when not to. Honestly, you're an amazing teacher, and man you own my respect.
    Bruh, this is some solid intermediate-level content! We definitely need more videos like this. They really help us get a better idea of writing clean code. Thanks again for all the effort you put into these!

  • @ayushshende4290
    @ayushshende4290 10 місяців тому +4

    Next tutorial can be a complete monorepo (like turborepo) with this stack, bonus add dockerization and deployment as well. Thanks for the amazing content.

  • @ourlifesgonnabesweetassugar
    @ourlifesgonnabesweetassugar 3 місяці тому +2

    Wabhhh this channel is gold man, why i never see till now man

  • @Hakanai2022
    @Hakanai2022 5 годин тому +1

    Do we need to include dist folder to .gitignore?

  • @Daniguy-p1b
    @Daniguy-p1b 9 днів тому

    for this typescipt with express first I visited your channel ☺....thanks a lot brother

  • @EpistemicFomo
    @EpistemicFomo 21 день тому

    So incredibly helpful! Thank you a lot!

  • @sayeddileri3461
    @sayeddileri3461 10 місяців тому +1

    Thank you so much Anson for this I am currently diving into testing and this is just perfect to help me get started. Thank you!!!

    • @ansonthedev
      @ansonthedev  10 місяців тому +1

      Glad to hear that. You're welcome. :D

  • @fabiospinelli4179
    @fabiospinelli4179 3 місяці тому

    Thank you very much for this video! I was a bit lost trying to set up TypeScript properly.

  • @SunwarulBERI
    @SunwarulBERI 13 днів тому

    Helped a lot. Thanks. Subscribed!

  • @rusted.dreams
    @rusted.dreams 3 місяці тому +2

    I was stuck in a bug where ts-node wont run and say couldn't recognize the file type '.ts' then I found out I was using type: moule in the package.json file which was causing the issue. I then removed it and it worked fine. I don't know there's an open issue in the ts-node repo about not working with module type!

  • @rupeshthapa8891
    @rupeshthapa8891 9 місяців тому +1

    This is very informative, thank you very much for the tutorial❤

  • @codingacumen4536
    @codingacumen4536 Місяць тому +1

    53:51 if your index.d.ts fiile is not executing make sure to include it in the tsconfig.json else you will not get the custom field

  • @kkbejoy
    @kkbejoy 2 місяці тому

    Hey Anson.. Really useful one.. Thanks a lot for creating such beautiful content...

  • @RatherBeCancelledThanHandled
    @RatherBeCancelledThanHandled 8 місяців тому +1

    Explained clearly ; well done 👍

  • @malikkadyraliev4871
    @malikkadyraliev4871 10 місяців тому

    U r best, hello from Kyrgyzstan, really appreciate ur videos 👍

  • @maximoignacio6959
    @maximoignacio6959 9 місяців тому +1

    Thank you very much!
    1:14:55
    import express from 'express';
    let app: ReturnType;
    should work as well.

  • @impulseimp1035
    @impulseimp1035 7 місяців тому

    Great tutorial. Helped me a lot, thanks man 👍

  • @Error404Codes
    @Error404Codes 10 місяців тому +3

    i got my server down when i declare the index.d.ts for extend request interface , the controller file did not show erro and ts knows the property but server goes down Property 'CustomField' does nto type 'Request

    • @jamesc3064
      @jamesc3064 6 місяців тому +3

      There's something about the way that the Request interface is extended globally that nodemon doesn't like. You can work around it using
      "start:dev": "nodemon --exec 'tsc && node dist/index.js' --ext ts"
      in your package.json

    • @gempf
      @gempf 5 місяців тому

      I have the same problem...

  • @johnattaiyinusa5766
    @johnattaiyinusa5766 10 місяців тому +1

    Great job, Anson

  • @iUmerFarooq
    @iUmerFarooq 10 місяців тому +2

    When are you going to upload an advance ExpressJs tutorial?
    Thanks for this awesome tutorial 💚

    • @ansonthedev
      @ansonthedev  10 місяців тому +2

      It's in the works. Thank you!

  • @emnznlg
    @emnznlg 2 місяці тому +1

    Hello, thanks for the video. It's amazing. Can you please let me know what font and which theme did you use in this video?

  • @SamOdiagbe
    @SamOdiagbe 4 місяці тому +2

    what theme is that, that's a pretty bold theme

  • @ミンテヨン
    @ミンテヨン 2 місяці тому +1

    hello. Thank you for the great lecture.
    I have one question. If I write return before res.status in the handler, an error occurs in the router. Can you tell me why?

  • @mohiwalla
    @mohiwalla 10 місяців тому +1

    Good job 👍👏

  • @letsspeakwithlearnenglish6371
    @letsspeakwithlearnenglish6371 2 місяці тому

    Great man, what extension are you using for intelligence.

  • @fola_azeez
    @fola_azeez 5 місяців тому

    This is amazing thank you so much.

  • @Boochie-n9c
    @Boochie-n9c 8 місяців тому

    Super helpful, thank you!

  • @riyad-appscode
    @riyad-appscode 10 місяців тому

    awesome tutorial. Thanks for the video

    • @ansonthedev
      @ansonthedev  10 місяців тому

      You're welcome. Thanks! :D

  • @Luke-Barrett
    @Luke-Barrett 4 місяці тому +2

    With the latest version of nodemon you don't need a separate install of ts-node. Nodemon will do the same thing for you.

  • @ayMillmusic
    @ayMillmusic 4 місяці тому

    Legend!

  • @aspirinemaga
    @aspirinemaga 4 місяці тому

    Thank you so much for sharing

  • @parth_patel2933
    @parth_patel2933 4 місяці тому

    amazing video. thanks a lot!

  • @jupiterjones1836
    @jupiterjones1836 Місяць тому

    Great work sir. THis helped me to use typescript with express seamlessly. Please, I would want to know what font you are using on this vscode. It is really nice. I want to use it too.

  • @kumarchandresh0
    @kumarchandresh0 5 місяців тому +1

    Which theme are you using?

  • @jayjaayjaaay94
    @jayjaayjaaay94 7 місяців тому

    1:05:46 how to differentiate one request to others?

  • @gunasekarant6498
    @gunasekarant6498 9 місяців тому

    Awesome one Thank you so much

  • @sdawdwadaufyuaiudi2148
    @sdawdwadaufyuaiudi2148 8 місяців тому

    almost every coures I find on youtube use any, only you explain what going in generic 40:17 ,thank .
    Is there any cheatsheat TypeScript for express,I can only cheatsheat for reactjs,it kinda suck

  • @ashutoshkummarr
    @ashutoshkummarr 5 місяців тому +1

    i'm getting unknown file extension with ts-node ,my type is set to "type" : "module

    • @codewithahk
      @codewithahk 4 місяці тому

      //tsconfig.json
      {
      "compilerOptions": {
      "target": "es2016",
      "module": "commonjs",
      "esModuleInterop": true,
      "forceConsistentCasingInFileNames": true,
      "strict": true,
      "skipLibCheck": true
      }
      }
      //package.json
      {
      "name": "backend",
      "version": "1.0.0",
      "main": "index.js",
      "scripts": {
      "build": "tsc",
      "start": "node ./dist/index.js",
      "dev" : "nodemon ./src/index.ts"
      },
      "author": "Ahmad Hassan Khan",
      "license": "ISC",
      "description": "",
      "devDependencies": {
      "@types/cors": "^2.8.17",
      "@types/express": "^4.17.21",
      "@types/node": "^22.5.4",
      "express": "^4.19.2",
      "nodemon": "^3.1.4",
      "ts-node": "^10.9.2",
      "typescript": "^5.5.4"
      },
      "dependencies": {
      "cors": "^2.8.5",
      "jsonwebtoken": "^9.0.2"
      }
      }

    • @tenshin_yozora
      @tenshin_yozora 3 місяці тому

      yoo I got the same case, were you able to resolve this?

  • @AdnanDev-su5no
    @AdnanDev-su5no 6 місяців тому

    Hey Anson, love your videos. Would you consider making a tutorial for fastify ?

  • @amatutoriel
    @amatutoriel 6 місяців тому +1

    Please your vs code extension ?

  • @masadsummair
    @masadsummair 9 місяців тому

    Thanks for rich content .
    I just want to ask how you learn these concept like nestjs and other along with best practices any sources?

    • @ansonthedev
      @ansonthedev  9 місяців тому +1

      When you're a beginner, it's fine to refer to UA-cam videos or courses on platforms like Udemy. When you become more advanced, you learn how to refer to documentation and build intuition with your experience.

  • @Jens1243
    @Jens1243 9 місяців тому

    Awesome tutorial!

  • @RobertMcGovernTarasis
    @RobertMcGovernTarasis 10 місяців тому

    Very clear, thank you. You’ve now got my toes wet with typescript. 1 question, how come when you ran npm run test:e2e it only ran 1 test for you, but for me it’s running both the e2e test, and the handler test?

    • @ansonthedev
      @ansonthedev  10 місяців тому +1

      My guess would be you may have forgot to set the flag for the test:e2e script to run tests only in the src/e2e folder. By default it will run all .test.ts or .spec.ts test files.

  • @prashlovessamosa
    @prashlovessamosa 10 місяців тому

    Thanks Anson.

  • @deathscythe3124
    @deathscythe3124 8 місяців тому

    How come you didn’t get an error when you name your user.ts router a const route then call it in index.ts as import userRouter. Im confuse. Please explain it to me

  • @jellyfish1772
    @jellyfish1772 9 місяців тому

    Thank you so much ..

  • @nithya4860
    @nithya4860 10 місяців тому +1

    Wow!

  • @igmtink
    @igmtink 10 місяців тому

    can you make a tutorial how to setup both nextjs + expressjs with typescript sir? like nextjs for frontend and expressjs with typescript for backend just a simple to-do or any

  • @smartdriver2990
    @smartdriver2990 10 місяців тому

    Wow, interesting 🎉

  • @paolo8114
    @paolo8114 22 дні тому

    Hi @Anson. Express does not let me overload response parameter with my own type. When setting my own interface as returned type, and trying to return it, im getting error that :
    The last overload gave the following error.
    Argument of type '(req: Request, res: Response) => Promise' is not assignable to parameter of type 'Application'.
    Even chatGPT could not solve it ;) Maybe u can outsmart it?

  • @maxmaul-pr2og
    @maxmaul-pr2og 5 місяців тому

    Hey anson, i was keeping up with your tutorials and they are very helpfull, i was wondering if you could make a class in nodejs rest api architecture?, like controller services and such, couldnt find any good tutorials online, mostly artricles with weak examples

    • @ansonthedev
      @ansonthedev  5 місяців тому

      By that point you’re better off just using Nestjs, which was designed with this architecture in mind. Which I also have plenty of videos on my channel.

    • @govindamishra3746
      @govindamishra3746 4 місяці тому

      Bro using Javascript classes in 2024

    • @ansonthedev
      @ansonthedev  4 місяці тому

      @@govindamishra3746 and there’s absolutely nothing wrong with that.

  • @chamaraweerasinghe3909
    @chamaraweerasinghe3909 9 місяців тому

    greate content keep up the good work

  • @mahmoudnada2120
    @mahmoudnada2120 9 місяців тому

    I hope you will make a live stream again with a program that is stronger than chat🌺

  • @nizarelfennani7477
    @nizarelfennani7477 4 місяці тому

    What font are you using there?

  • @abhayshaw1875
    @abhayshaw1875 10 місяців тому

    Hey can we have a video on an opionated one :adonis js??

    • @marcschiavone9549
      @marcschiavone9549 10 місяців тому

      I believe it doesnt make much sense since here they explain the whole typescript + express setup and adonisjs is already typescript ready.

  • @mythmaker6155
    @mythmaker6155 9 місяців тому

    I am sorry to ask you this. but I am new to Express with TypeScript. i worked with django. But for expanding my tech stack i am learning to express the best way. One thing i loved in django(Django-ninja) was automatic API documentation. is there any way to achieve similar functionality in Express? I did search API documentation with Express but all I find is manual documentation. If there is any way to automatically generate documentation with Joi or TS interface it would be really helpful.
    BTW love the video. it got me started TS with Express

    • @ansonthedev
      @ansonthedev  9 місяців тому +1

      There is Swagger, not sure about it being automatic, but it does provide documenting your APIs for you.

  • @prerakhere
    @prerakhere 8 місяців тому

    I don't understand when to use express-serve-static-core v/s express

    • @codewithahk
      @codewithahk 4 місяці тому

      Typically, you won't directly import or interact with express-serve-static-core. It is used internally by Express. However, if you are writing TypeScript or creating TypeScript types for your Express application, you might import types from express-serve-static-core, as it contains TypeScript definitions for core Express objects.

    • @codewithahk
      @codewithahk 4 місяці тому

      if you're not doing any low-level Express manipulation or using TypeScript, you can ignore express-serve-static-core and focus on using express

  • @thezeeshann
    @thezeeshann 4 місяці тому

    Bro can you please make a video on typescript with react, and react query humble request 😢🙏

    • @ansonthedev
      @ansonthedev  4 місяці тому +2

      I have a video on react query already that will be uploaded soon.

  • @devfabien
    @devfabien 9 місяців тому

    This is an amazing tutorial.
    I would like to seek your recommendation; based on what you showed in tutorial most in the part of e2e test what is your point of view in using `App` type from supertest/types instead of assigning variable app to `Express` type. ua-cam.com/video/Be7X6QJusJA/v-deo.html

    • @ansonthedev
      @ansonthedev  9 місяців тому +1

      I used "Express" because that's the inferred type from the express() function call that is returned. Never knew there was an App type. But I never had any issues using the Express type.

  • @FreeFire-kingfire
    @FreeFire-kingfire Місяць тому

    bro, what font are u using?