The Complete Guide To Building A REST API With Node, Express, TypeScript & MongoDB + Authentication

Поділитися
Вставка
  • Опубліковано 26 лис 2024

КОМЕНТАРІ • 351

  • @off-samuelGYZ
    @off-samuelGYZ 4 місяці тому +36

    3:02 The "moduleResolution: node" was deprecated, so instead using "node" it's helpful use "NodeNext" or leave without definition.
    Awesome tutorial, you helped me a lot!

    • @JoSh-yu6jt
      @JoSh-yu6jt 3 місяці тому

      Did everything work for you? I'm getting a 400 Bad Request in postman when I'm trying to register a new user. 🤔

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

      @@JoSh-yu6jt Make sure you send your request (through postman) in JSON format.

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

      I've typed NodeNext on both

  • @oladapodaniel6372
    @oladapodaniel6372 10 місяців тому +14

    I just completed this video, I can say confidently that it's an outstanding video, it has skyrocketed my knowledge in node, and my ability to create REST API, structure my directories correctly, and lots more. Thank you so much Antonio🙏

  • @springerbarry7723
    @springerbarry7723 Рік тому +6

    As a front end developer, I finally finish This REST API tutorial in a week. Great Great! Thank you very much! I will conquer all your courses One at a time! Really having fun coding with you Antonio!

    • @codewithantonio
      @codewithantonio  Рік тому +1

      Thank you for watching the tutorial!

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

      @@codewithantonio hello Antonio! BIG THANKS for thios video, but i have a question. why are you using http here, when u can just put app.listen and server is going to work? im not blaming, jsut cant get it

  • @AliAliOxenFree
    @AliAliOxenFree Рік тому +36

    This is an outstanding video. Most of my work has been with Nestjs and postgres, but this gave me a clear perspective on a different approach to handle the same REST endpoints. earned yourself a loyal sub!

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

    Hi Antonio. I found your channel recently and completed coding the REST API. I learnt alot and amused with the way you explain & code all the stuff. I hadn't found a channel like yours before. However It's all super clean❤ You deserve more followers than you have rn. Keep up the great work🤍🥂 Lots of love from Sri Lanka🇱🇰

  • @gtechlabs7
    @gtechlabs7 Рік тому +5

    best tutorial on API ts. clean and straight forward no bs. Thanks a lot.

  • @vadimbondarenko7416
    @vadimbondarenko7416 11 місяців тому +6

    Man, your videos are treasure. UA-cam should have added respect button. Thank you!

  • @vidazarei3951
    @vidazarei3951 7 місяців тому +1

    I want to show my appreciation for your useful video,I highly recommend to every person who is looking for do complete CRUD with Node,this video is so handy and you can get whatever you need for your REST API.

  • @bongjames2222
    @bongjames2222 Рік тому +7

    Wow~~
    This is the course I was looking for.
    I wanted to see a lecture made with node typescript
    thank you.
    I should have seen this lecture sooner.
    I used google translator.

  • @WagnerDueñas
    @WagnerDueñas 7 місяців тому +1

    Your tutorial has been the most useful for me!

  • @SurajBhanMundotiya-e2j
    @SurajBhanMundotiya-e2j Рік тому +3

    Very clean and crisp video Antonio, that's what a good dev and guide should do, gonna watch more content and learn from your channel.

  • @kwasiezor1630
    @kwasiezor1630 Рік тому +12

    Great video. It's just clean, easy to understand and straightforward. Thanks and keep it up 👍

  • @q5850
    @q5850 Рік тому +1

    perfect, I love this channel. Thanks to god, I discovered this channel

  • @4dev346
    @4dev346 Рік тому +1

    I was able to run the findByIdAndUpdate even though it was not included at the video. Thanks for a very clear and smooth tutorial.

  • @codewithantonio
    @codewithantonio  Рік тому +20

    Thank you so much for watching my first tutorial. All the code is available here github.com/AntonioErdeljac/ts-node-mongo-rest-api-tutorial, and in the description. If you noticed any mistakes, bugs or wish for anything to be improved, please write in the comments below, I would be happy to improve! ❤

    • @machuwey
      @machuwey 7 місяців тому +3

      Nah bruv, error 404

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

    Great Video Antonio. One quick thing for others, you don't need body parser as separate package with latest express (>v4), express inbuilts it

  • @off-samuelGYZ
    @off-samuelGYZ 4 місяці тому

    I've had having some trouble getting my code to run properly. My main two issues were with user login and checking if an email already exists in the database.
    My solution was to import the 'User Model' into my controller file and use the findOne method. That little fix did the trick.
    I'm a junior software developer, so don't get mad at me, seniors software enginnering! lol!

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

    Great tutorial. For those that didn't follow it exactly, I had strict: true in my tsconfig.json. This caused TS to complain about the authentication controller file. user.authentication and user.authenticaion.salt could be null or undefined. To fix, just add a few more checks in: if (!user) statement. It should be something like: if (!user || !user.authentication || !user.authentication.salt) that solved it for me.

  • @rainyuuu
    @rainyuuu Рік тому +1

    Thank you for this video!! I am a backend noob and this guide helped me a lot! So glad that I came across your video.

  • @raiyanthedeveloper
    @raiyanthedeveloper Рік тому +1

    Thanks a lot for explaining so quickly. Wating for your vidoes. Love from Bangladesh.

  • @volodymyrmatselyukh8808
    @volodymyrmatselyukh8808 Рік тому +1

    Pretty interesting stuff. I was looking for Graph QL but landed on this video and couldn't quit) A great video for baking a boilerplate for future projects. Thanks.

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

    So helpful Antonio, you're so great.
    but remember that now body parser is deprecated

  • @gaminghta333
    @gaminghta333 Рік тому +3

    Great video - I love this video about nodejs typescript

  • @attaullahsiddiqui3931
    @attaullahsiddiqui3931 Рік тому +1

    Very good. Waiting for more videos like these for Angular, Node(advanced), Flutter

  • @mktNo1
    @mktNo1 Рік тому +1

    I'm a newbie. It's really helpful. Thank you so much.

  • @Liam-vn1fp
    @Liam-vn1fp Рік тому +1

    Thanks for this USEFUL REST API GUIDE

  • @kwasiezor1630
    @kwasiezor1630 Рік тому +34

    For the next videos, Can you please Add mongodb all relationships such as one to one, one to many and many to many. It's a topic in which I have lot interest. Thanks

    • @codewithantonio
      @codewithantonio  Рік тому +5

      Thank you so much for the suggestion! I will make sure to put it on my list

    • @RebaiMoez
      @RebaiMoez Рік тому +3

      MongoDb is no sql database so basically there’s no relation between collections

    • @trackntrail2869
      @trackntrail2869 Рік тому

      @@RebaiMoez There can be relations between collections in document DBs. While it is advisable to denormalize, there are certainly scenarios where you would query a collection by FK.

    • @gibsonsgibson1513
      @gibsonsgibson1513 Рік тому +2

      ​@@RebaiMoezactually it is possible to create relationships.

    • @ebenezersiaw935
      @ebenezersiaw935 Рік тому

      ua-cam.com/video/StrwQFdxudQ/v-deo.htmlsi=gJsfvd_ndHo_i5DU

  • @BalamuruganThanikachalam
    @BalamuruganThanikachalam Рік тому +1

    Thanks a lot Antonio for the video. Learnt few new things like no jwt, storing token in the cookie.

  • @markus_dev_cwb
    @markus_dev_cwb Рік тому +2

    Amazing API video. Very easy to understand and clean code to learn! Thanks Man!

  • @mennatallakhougha8614
    @mennatallakhougha8614 11 місяців тому +1

    Very simple and easy to follow along thank you amazing video

  • @amanmalik781
    @amanmalik781 Рік тому +2

    Thank You so much, really needed this

  • @ryanzhouff
    @ryanzhouff Рік тому +1

    Thanks for sharing this great video.Learned a lot.

  • @bartoszgauszka7021
    @bartoszgauszka7021 Рік тому +1

    thanks for this tutorial, it made me a lot easier to setup TS with express and use it 😃😃

  • @gopikrishnag41
    @gopikrishnag41 Рік тому +1

    Very straight forward and easy to understand, thx

  • @mohammadaminreihani5704
    @mohammadaminreihani5704 6 місяців тому

    Such an amazing tutorial. Thank you Antonio! 😍👋

  • @JamesVannordstrand
    @JamesVannordstrand Рік тому +1

    I love your stuff. Keep up the great work. You're an amazing teacher and these simple tutorials are awesome.

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

    Hello Antonio, really nice video. i loved

  • @theovdhd
    @theovdhd Рік тому +23

    Good tutorial but it might be more helpful to also mention what certain parts of the code are doing and why they're there. At one point, a line is added that is "extremely important" or else the code will not work. It would be nice to get some explanation about why that is exactly.

    • @codewithantonio
      @codewithantonio  Рік тому +17

      I full agree, this was my first video and I didn't really know what I was doing, thank you for the feedback!

    • @anonymous_basics
      @anonymous_basics 11 місяців тому

      i also felt same.

  • @canra245
    @canra245 4 місяці тому +1

    finally no error, thank you

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

    great video. very helpful. thanks

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

    great content with easy explanation.

  • @chetanrana7778
    @chetanrana7778 Рік тому +2

    Excellent Tutorial

  • @MatiasNovillo1
    @MatiasNovillo1 11 місяців тому +2

    EXCELLENTE sir! Thanks!

  • @lucasdamasceno7068
    @lucasdamasceno7068 Рік тому +2

    great project. thanks bro, i gonna put this on my portfolio

  • @victorsmilyborgesalmonte8418

    Very cool the way you handle the router!! You got a like and a follow!

  • @razibulhossen9680
    @razibulhossen9680 Рік тому +1

    Amazing wait for next video

  • @GabrielAlves-ci3zr
    @GabrielAlves-ci3zr Рік тому +15

    Great video! i was struggling with back-end and this really cleared my mind. What would you recommend when it comes to testing? A video focused on TDD with typescript would be great :)

    • @codewithantonio
      @codewithantonio  Рік тому +15

      Happy you liked the video! I will perhaps make a more in-depth tutorial about testing in the future

    • @leavs
      @leavs Рік тому

      @@codewithantonio

    • @ekerekeprecious5571
      @ekerekeprecious5571 Рік тому

      Anticipating this @@codewithantonio

    • @swastikpatro6436
      @swastikpatro6436 11 місяців тому

      Hey Antonio, a video on TDD will be highly appreciated🙏❤

  • @bassam.2023
    @bassam.2023 Рік тому +3

    This really was a great tutorial. 😀🙏🏼
    The front-end counterpart tutorial to this (React, Next, or HTML/JS) should be short and quick, and would be extremely useful. Thanks!

  • @hanifbahari6606
    @hanifbahari6606 Рік тому +1

    amazing, easy to follow and pleasant to listen.

  • @stefanocons
    @stefanocons Рік тому +1

    Loved this tutorial! Thanks a lot man!

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

    You are a pro man.

  • @ImamNurArifinHA
    @ImamNurArifinHA Рік тому +2

    Great video,, you explained it clearly,, i have subscribed

  • @irvanmaulana1302
    @irvanmaulana1302 Рік тому +1

    omg I learned a lot from this video, thanks a lot!

  • @aswarthanarayanareddyb176
    @aswarthanarayanareddyb176 Рік тому +1

    Great Tutorial, thanks for nice tutorial 💌

  • @arpan157
    @arpan157 Рік тому +44

    Personally, I would not suggest it for beginners; there is little to no explanation and it might be quite daunting for those of you who are just getting started.

    • @L.K.82
      @L.K.82 Рік тому +3

      Very true. Thought exactly the same.

    • @Abu_Rayhan
      @Abu_Rayhan Рік тому

      I thought the same

    • @riyayadav8468
      @riyayadav8468 Рік тому +5

      I'm beginner but I understand pretty well I like it ❤

    • @omkarambure9779
      @omkarambure9779 11 місяців тому

      @arpan157 do you know any other good videos on express js?

    • @Badis-n2u
      @Badis-n2u 11 місяців тому

      But which is better ?
      This or the simple express.js

  • @oscarwanga4453
    @oscarwanga4453 Рік тому +1

    amazing work really helped me a lot. Thank you

  • @xuanthangle8207
    @xuanthangle8207 Рік тому +1

    Your content is good, keep create more content about nodejs with TS but in the real life, it will be great

  • @naathan4455
    @naathan4455 Рік тому +1

    You saved my life. Thanks

  • @codewithantonio
    @codewithantonio  Рік тому +21

    Want to get mentored by me? Apply at www.codewithantonio.com/mentorship
    Hi! I created a Discord channel where you can ask me any questions if you got stuck in my tutorials: discord.gg/SPEBvAz4Vd

  • @alimezghani9239
    @alimezghani9239 Рік тому +2

    Mate this is awesome

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

    Excellent explanation!

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

      Thank you!

    • @sarfrazshah5158
      @sarfrazshah5158 6 місяців тому

      @@codewithantonio Oh! can you please tell me what VS Code theme you use? I just loved it....

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

      @@sarfrazshah5158 Monokai Pro!

    • @sarfrazshah5158
      @sarfrazshah5158 6 місяців тому

      @@codewithantonio Thank you Sir!

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

    Aspects of this no longer work with express 5, so if you are getting overload errors in your router files, you can downgrade to express 4.x.x or include next after res and req in the definition.
    Thanks for the tutorial!

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

      could you paste your code to see what you mean by including next after res and req, plss

  • @adamt4110
    @adamt4110 11 місяців тому

    create user returns 200. GOOD job!

  • @CliveStewart-bq3od
    @CliveStewart-bq3od Рік тому +2

    Would really want to see a guide to building a REST API with TypeScript + MYSQL(Larvel) + Authentication

  • @L.K.82
    @L.K.82 Рік тому +5

    At around minute 32 I get errors: user.authentication.salt, .password and .sessionToken are "possibly undefined". I checked my users.ts file and it seems to be exactly the same as yours. What do I have to do in order to make this error disappear?

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

      One way woudl be to add an explicit guard check like so:
      if (!user || !user.authentication || !user.authentication.salt) {
      return res.sendStatus(400);
      }

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

      ​@@JonnyCage77i can't even save please help me...

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

      Bro did u fixed it if s how...??

  • @peapuffer3514
    @peapuffer3514 Рік тому +1

    And just like that I completed the tutorial successfully. Thanks for the video

  • @martinmendez695
    @martinmendez695 Рік тому

    Good video, I would recommend to use the command [ npx tsc --init ] instead of creating the tsconfig.js from scratch.

  • @hacksbsb
    @hacksbsb Рік тому

    Wow this tutorial really saves me cause I have a interview about it. If you have time, could you please do a MEAN/MERN based on this tutorial?

  • @vincenzoriwu2998
    @vincenzoriwu2998 Рік тому +1

    Thank you, very useful using ts

  • @thequang9234
    @thequang9234 Рік тому +3

    Do more backend tutorials !!

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

    Great work, thank you @codewithantonio 🤗

  • @skbhati199
    @skbhati199 Рік тому +1

    excellent video I need videos for socials login🥰🥰

    • @codewithantonio
      @codewithantonio  Рік тому

      Thank you! If you are interested in NextJS, I have a couple of tutorials which do social login there

  • @awesomeguy6427
    @awesomeguy6427 Рік тому +4

    Can u please more videos on express Node backend and production deployment.

  • @roebienarnaiz
    @roebienarnaiz Рік тому +1

    Great Video!

  • @pedroaviladressler310
    @pedroaviladressler310 Рік тому +1

    do you have any recomendations on where do I learn the basics os authentication and password encrypting?

  • @rima-t
    @rima-t Рік тому +1

    Do we need the "mongoose.Promise = Promise;" line? and what does it do? thank you very much

  • @thecodereviewer
    @thecodereviewer Рік тому

    Great great job! 😊

  • @jorgerenteral
    @jorgerenteral Рік тому +1

    Awesome man, new follower, and if you create a paid course, I'm in for buying it 🤘🏽

  • @K.Huynh.
    @K.Huynh. 8 місяців тому +1

    thank you for sharing!

  • @Noritoshi-r8m
    @Noritoshi-r8m Рік тому +1

    Great stuff! Many thx

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

    thanks a lot Antonio ❤ can you create a video about handling role permission with middlewares to?

  • @IngPedroAraujo
    @IngPedroAraujo Рік тому +1

    Thanks for sharing your knowledge.. I've got an error on the tsconfig.ts file the property "moduleResolution": "node",

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

      ^ The only one of these comments actually following along.
      His TS Config is broken....

  • @RwandaBruno
    @RwandaBruno 7 місяців тому +1

    Thanks very much ❤❤❤

  • @azizraja5436
    @azizraja5436 5 днів тому

    Excellent

  • @juanantoniovivaldy
    @juanantoniovivaldy Рік тому +1

    what is the differences between httpServer.listen() and app.listen(), the first is using http modules, and express framework?

  • @shueiyang6431
    @shueiyang6431 Рік тому

    Nice tutorial for this in typescript, for unknown reason the post is deleted, so i write again, haven't go throught it but just notice you still use bodyparser, since 4.0 express have already integrated it, so you don't need anymore and you can replace the middleware with express.json() :)

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

    sir antonio can you make a masterclass for this, like "next-auth" like having a logic to implementing "email verification, password reset, otp, oauth provider, role base"

  • @AndreSpecht
    @AndreSpecht Рік тому +1

    Amazing video. Could you show us how to deploy it properly? Like on Netlify. Also, are u planning a React course in the near future? Thnaks

    • @barcalover016
      @barcalover016 Рік тому

      you cannot deploy server side applications like this API to netlify, unless you deploy it as serverless function. although you can easily deploy it to render. but render doesn't allow your server to run all the time it shuts down after 15s from last call, and it takes too long to restart and send back response when you call it again after 15 min. better alternative is vercel but you have to configure some files to be able to deploy an api to it.

  • @angr7
    @angr7 Рік тому +1

    Hi, Antonio! thx for a nice tutor!
    As a cpp backend dev (no experience in web) I'm wondering, why not use OpenApi notation for API declaration and sever creation?

  • @abenezermaru6276
    @abenezermaru6276 Рік тому +1

    i watch your videos they well put together with advanced development practice but can you do a more in depth explanation tutorial for some us are not following at some instance

  • @virgineftw9013
    @virgineftw9013 Рік тому

    good stuff i like the fact that you used typescript in the backend , the only thing that i maybe not fan of is the naming for the files too many index.ts and file structure im kinda lost , maybe a sperated files models/controllers/routes would be nice. since the more complexity we add to a certain project, the more files we have, it would be chaos. it maybe comes back to personal preference idk. overall good job ❤‍🔥❤‍🔥

  • @Salah-YT
    @Salah-YT Рік тому +2

    thank u so much

  • @spalk125
    @spalk125 Рік тому +2

    Hello Antonio and thank you for the great content. I have watched until 33:41 (end of authentication) and I have some questions.
    1) Isn't it better to use bcrypt instead of crypto for hashed passwords?
    2) Isn't it better to use a .env file to save your passwords instead of using them directly in code?
    3) Isn't it safer to use jwt instead of this session token?
    4) Shouldn't the cookie and the token have expiration dates?
    5) Like this is the authentication safe enough to use against common hacking attacks?

    • @caedencode
      @caedencode Рік тому

      It is better, Its safer and JWT Is better and cookies do have expiration dates.

  • @akshaysrivastava4304
    @akshaysrivastava4304 11 місяців тому

    Hi there !
    I would like to address a bug which I encountered while following this tutorial.
    If anyone is getting the following error in their app:
    Error: Cannot find module 'helpers'
    Require stack:....
    Then you need to fix your imports from this -
    import { authentication, random } from "helpers";
    to this
    import { authentication, random } from "../helpers";
    For these '../' I spend a lot of time debugging. Thanks for the tutorial Antonio.

  • @bouabahmed3525
    @bouabahmed3525 Рік тому +1

    Great video, thanks a lot

  • @feitan8745
    @feitan8745 Рік тому +1

    The thing about storing salts is a very old concept that was discarded, it discouraged, unless something has changed and i don't know, you just don't need to save it.

    • @codewithantonio
      @codewithantonio  Рік тому

      Thank you for pointing this out! I will take a look at my decisions in this video and see how it can be improved, I actually did not use salt as you said in my Netflix and Twitter tutorial, so you're probably right :)

  • @SatryaNouvanda
    @SatryaNouvanda Рік тому

    Great video. Why you merge two objects and using identity key in isAuthenticated method in middleware? Thanks in advance.

  • @everbliss7955
    @everbliss7955 Рік тому +2

    Tutorial is great! Thanks alot. Just some thing to note, I find that you sometimes just say WHAT you are doing but you don't explain WHY.

  • @marcelooliveira1541
    @marcelooliveira1541 Рік тому +1

    why use MongoDB for users? isn't it better to use a relational DB like PostgreeSQL with prisma so users can have relations?

  • @bayandamabuza6587
    @bayandamabuza6587 Рік тому +2

    I'm stuck on "user.authentication possibly 'undefined' " it shows an error

    • @gcma1999
      @gcma1999 Рік тому

      Make sure your "tsconfig.json" filename is spelled correctly.