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

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 มิ.ย. 2024
  • Discord for any problems/errors/bugs: www.codewithantonio.com/discord
    Github & Live Website: www.codewithantonio.com/proje...
    In this video, we will be building a REST API with Node.js, Express and TypeScript. We will also be using MongoDB as our database. This is a complete guide that will take you from start to finish in creating a working REST API.
    Timestamps
    00:00 Intro
    00:28 Environment setup
    04:43 Setup Express server
    08:18 MongoDB Setup
    12:26 Creating User Model
    18:13 Helpers for authentication
    20:30 Authentication controllers
    25:02 Authentication routing and logging in
    33:44 Middelware creation
    37:31 Users controller and routing
    48:55 Wrap up

ความคิดเห็น • 325

  • @oladapodaniel6372
    @oladapodaniel6372 5 หลายเดือนก่อน +7

    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🙏

  • @AliAliOxenFree
    @AliAliOxenFree ปีที่แล้ว +31

    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!

  • @codewithantonio
    @codewithantonio  ปีที่แล้ว +20

    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

  • @codewithantonio
    @codewithantonio  ปีที่แล้ว +17

    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 หลายเดือนก่อน +1

      Nah bruv, error 404

  • @JamesVannordstrand
    @JamesVannordstrand 9 หลายเดือนก่อน +1

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

  • @user-ej6wd5ey9s
    @user-ej6wd5ey9s ปีที่แล้ว +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.

  • @vidazarei3951
    @vidazarei3951 หลายเดือนก่อน +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.

  • @springerbarry7723
    @springerbarry7723 ปีที่แล้ว +3

    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  ปีที่แล้ว

      Thank you for watching the tutorial!

    • @vladyslavfereira6931
      @vladyslavfereira6931 3 หลายเดือนก่อน

      @@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

  • @kwasiezor1630
    @kwasiezor1630 ปีที่แล้ว +12

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

  • @irumidisara9547
    @irumidisara9547 3 หลายเดือนก่อน

    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🇱🇰

  • @volodymyrmatselyukh8808
    @volodymyrmatselyukh8808 9 หลายเดือนก่อน

    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.

  • @kalombograce2677
    @kalombograce2677 11 หลายเดือนก่อน +4

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

  • @attaullahsiddiqui3931
    @attaullahsiddiqui3931 6 หลายเดือนก่อน +1

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

  • @vadimbondarenko7416
    @vadimbondarenko7416 6 หลายเดือนก่อน +5

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

  • @victorsmilyborgesalmonte8418
    @victorsmilyborgesalmonte8418 9 หลายเดือนก่อน

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

  • @mohammadaminreihani5704
    @mohammadaminreihani5704 หลายเดือนก่อน

    Such an amazing tutorial. Thank you Antonio! 😍👋

  • @user-xj1ei4mm5j
    @user-xj1ei4mm5j 2 หลายเดือนก่อน

    Your tutorial has been the most useful for me!

  • @markus_dev_cwb
    @markus_dev_cwb ปีที่แล้ว +2

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

  • @rainyuuu
    @rainyuuu 10 หลายเดือนก่อน +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.

  • @bongjames2222
    @bongjames2222 ปีที่แล้ว +5

    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.

  • @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.

  • @q5850
    @q5850 7 หลายเดือนก่อน +1

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

  • @gaminghta333
    @gaminghta333 ปีที่แล้ว +3

    Great video - I love this video about nodejs typescript

  • @gopikrishnag41
    @gopikrishnag41 ปีที่แล้ว +1

    Very straight forward and easy to understand, thx

  • @mennatallakhougha8614
    @mennatallakhougha8614 6 หลายเดือนก่อน +1

    Very simple and easy to follow along thank you amazing video

  • @hanifbahari6606
    @hanifbahari6606 ปีที่แล้ว +1

    amazing, easy to follow and pleasant to listen.

  • @ryanzhouff
    @ryanzhouff 6 หลายเดือนก่อน +1

    Thanks for sharing this great video.Learned a lot.

  • @amanmalik781
    @amanmalik781 8 หลายเดือนก่อน +2

    Thank You so much, really needed this

  • @mktNo1
    @mktNo1 ปีที่แล้ว +1

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

  • @angaragg.3165
    @angaragg.3165 2 หลายเดือนก่อน

    This is a great video. You did a good job.

  • @stefanocons
    @stefanocons ปีที่แล้ว +1

    Loved this tutorial! Thanks a lot man!

  • @Liam-vn1fp
    @Liam-vn1fp 11 หลายเดือนก่อน +1

    Thanks for this USEFUL REST API GUIDE

  • @user-ez5ch8qn3p
    @user-ez5ch8qn3p ปีที่แล้ว +1

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

  • @lucasdamasceno7068
    @lucasdamasceno7068 ปีที่แล้ว +2

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

  • @raiyanthedeveloper
    @raiyanthedeveloper ปีที่แล้ว +1

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

  • @MatiasNovillo1
    @MatiasNovillo1 6 หลายเดือนก่อน +1

    EXCELLENTE sir! Thanks!

  • @bartoszgauszka7021
    @bartoszgauszka7021 ปีที่แล้ว +1

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

  • @ImamNurArifinHA
    @ImamNurArifinHA ปีที่แล้ว +2

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

  • @aswarthanarayanareddyb176
    @aswarthanarayanareddyb176 8 หลายเดือนก่อน +1

    Great Tutorial, thanks for nice tutorial 💌

  • @ValdirCastaldelliJr
    @ValdirCastaldelliJr 3 หลายเดือนก่อน +1

    Hello Antonio, really nice video. i loved

  • @irvanmaulana1302
    @irvanmaulana1302 8 หลายเดือนก่อน +1

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

  • @oscarwanga4453
    @oscarwanga4453 ปีที่แล้ว +1

    amazing work really helped me a lot. Thank you

  • @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 10 หลายเดือนก่อน

      @@codewithantonio

    • @ekerekeprecious5571
      @ekerekeprecious5571 9 หลายเดือนก่อน

      Anticipating this @@codewithantonio

    • @swastikpatro6436
      @swastikpatro6436 6 หลายเดือนก่อน

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

  • @muditkhanna8164
    @muditkhanna8164 3 หลายเดือนก่อน +1

    great content with easy explanation.

  • @chetanrana7778
    @chetanrana7778 11 หลายเดือนก่อน +2

    Excellent Tutorial

  • @user-yn9yr8hq8v
    @user-yn9yr8hq8v 2 หลายเดือนก่อน +1

    Thanks very much ❤❤❤

  • @K.Huynh.
    @K.Huynh. 3 หลายเดือนก่อน +1

    thank you for sharing!

  • @vincenzoriwu2998
    @vincenzoriwu2998 11 หลายเดือนก่อน +1

    Thank you, very useful using ts

  • @sarfrazshah5158
    @sarfrazshah5158 หลายเดือนก่อน +1

    Excellent explanation!

    • @codewithantonio
      @codewithantonio  หลายเดือนก่อน +1

      Thank you!

    • @sarfrazshah5158
      @sarfrazshah5158 หลายเดือนก่อน

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

    • @codewithantonio
      @codewithantonio  29 วันที่ผ่านมา +1

      @@sarfrazshah5158 Monokai Pro!

    • @sarfrazshah5158
      @sarfrazshah5158 29 วันที่ผ่านมา

      @@codewithantonio Thank you Sir!

  • @thecodereviewer
    @thecodereviewer 7 หลายเดือนก่อน

    Great great job! 😊

  • @gherardivictor
    @gherardivictor 3 หลายเดือนก่อน

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

  • @bassam.2023
    @bassam.2023 9 หลายเดือนก่อน +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!

  • @razibulhossen9680
    @razibulhossen9680 ปีที่แล้ว +1

    Amazing wait for next video

    • @codewithantonio
      @codewithantonio  ปีที่แล้ว

      Thank you a lot! New video is coming soon!

  • @codingintelugu8820
    @codingintelugu8820 4 หลายเดือนก่อน +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

  • @Woeden
    @Woeden ปีที่แล้ว +1

    Great stuff! Many thx

  • @virgineftw9013
    @virgineftw9013 7 หลายเดือนก่อน

    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

  • @xuanthangle8207
    @xuanthangle8207 ปีที่แล้ว +1

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

  • @kwasiezor1630
    @kwasiezor1630 ปีที่แล้ว +35

    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 11 หลายเดือนก่อน +2

      ​@@RebaiMoezactually it is possible to create relationships.

    • @ebenezersiaw935
      @ebenezersiaw935 8 หลายเดือนก่อน

      th-cam.com/video/StrwQFdxudQ/w-d-xo.htmlsi=gJsfvd_ndHo_i5DU

  • @naathan4455
    @naathan4455 ปีที่แล้ว +1

    You saved my life. Thanks

  • @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?

  • @frontend_ko
    @frontend_ko 11 หลายเดือนก่อน

    very nice video, thanks

  • @martinmendez695
    @martinmendez695 9 หลายเดือนก่อน

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

  • @alimezghani9239
    @alimezghani9239 ปีที่แล้ว +2

    Mate this is awesome

  • @bouabahmed3525
    @bouabahmed3525 ปีที่แล้ว +1

    Great video, thanks a lot

  • @rohitcpathare
    @rohitcpathare 10 หลายเดือนก่อน

    This is great! In the future can you also make a video using MongoDB with GraphQL?

  • @roebienarnaiz
    @roebienarnaiz ปีที่แล้ว +1

    Great Video!

  • @mahedihassanshawon4821
    @mahedihassanshawon4821 10 หลายเดือนก่อน +1

    thanks!

  • @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  ปีที่แล้ว +16

      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 5 หลายเดือนก่อน

      i also felt same.

  • @CliveStewart-bq3od
    @CliveStewart-bq3od ปีที่แล้ว +3

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

  • @denysaheienko7177
    @denysaheienko7177 5 หลายเดือนก่อน +1

    Great work, thank you @codewithantonio 🤗

  • @shueiyang6431
    @shueiyang6431 11 หลายเดือนก่อน

    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() :)

  • @angr7
    @angr7 9 หลายเดือนก่อน +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?

  • @jorgerenteral
    @jorgerenteral ปีที่แล้ว +1

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

  • @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

  • @ecoutret5214
    @ecoutret5214 11 หลายเดือนก่อน

    Hi! Thanks for this tutorial, very well explained! I have a question regarding APIs with NextJS. I have a project with NextJs 13 and all the api endpoints are done. I’m using next-auth to authenticate my users. Now I want to develop a mobile app with react native, I would like to know if I can use my next js api endpoints to fetch my data? How can I authenticate my users from the mobile app? I don't know if I should develop a new backend with apis and authentication etc...

  • @peapuffer3514
    @peapuffer3514 11 หลายเดือนก่อน +1

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

  • @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

  • @SatryaNouvanda
    @SatryaNouvanda ปีที่แล้ว

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

  • @adamt4110
    @adamt4110 6 หลายเดือนก่อน

    create user returns 200. GOOD job!

  • @go_forward140
    @go_forward140 ปีที่แล้ว +1

    thank you

  • @MariemMili
    @MariemMili ปีที่แล้ว +1

    thanks good job😃

    • @codewithantonio
      @codewithantonio  ปีที่แล้ว

      Glad you like it!

    • @MariemMili
      @MariemMili ปีที่แล้ว

      ​@@codewithantonio hi i'm wondering why when i change the name ANTONIO with another name it gives me Bad Request

    • @MariemMili
      @MariemMili ปีที่แล้ว

      I changed it in all the places where it has occurred

  • @AndreSpecht
    @AndreSpecht 8 หลายเดือนก่อน +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 7 หลายเดือนก่อน

      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.

  • @pedroaviladressler310
    @pedroaviladressler310 8 หลายเดือนก่อน +1

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

  • @adnanamin3666
    @adnanamin3666 ปีที่แล้ว +1

    Just subbed! :)

  • @theproactivemindset
    @theproactivemindset 11 หลายเดือนก่อน

    Antonio, one question, how did you get an actual arrow when you create and arrow function, it's with an extension?

  • @mehdifassifihri5951
    @mehdifassifihri5951 ปีที่แล้ว +1

    Really good content i really like the way you code bro !! can you do a tutorial about jwt token ?

    • @codewithantonio
      @codewithantonio  ปีที่แล้ว

      Thank you! In the future i will probably have more tutorials like that and with jwt token for sure

  • @igmtink
    @igmtink 2 หลายเดือนก่อน

    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"

  • @arpan157
    @arpan157 11 หลายเดือนก่อน +34

    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 10 หลายเดือนก่อน +2

      Very true. Thought exactly the same.

    • @Abu_Rayhan
      @Abu_Rayhan 7 หลายเดือนก่อน

      I thought the same

    • @riyayadav8468
      @riyayadav8468 6 หลายเดือนก่อน +3

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

    • @omkarambure9779
      @omkarambure9779 6 หลายเดือนก่อน

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

    • @user-wr7ou8ih5s
      @user-wr7ou8ih5s 6 หลายเดือนก่อน

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

  • @thequang9234
    @thequang9234 ปีที่แล้ว +3

    Do more backend tutorials !!

    • @codewithantonio
      @codewithantonio  ปีที่แล้ว +1

      Will do in the future! Thank you for watching!

  • @aminurmudanasution5813
    @aminurmudanasution5813 หลายเดือนก่อน

    Hi Antonio, what an amazing video
    can you spill the extension/plugin of your terminal, so i can get suggestion of command like in 6:55? Thanks!!

  • @w1nchester551
    @w1nchester551 9 หลายเดือนก่อน

    what font settings do you use in vscode to have ligatures? I tried cascadia code and firecode, but with them the font became somehow bold.

  • @tiagorodrigues1617
    @tiagorodrigues1617 4 หลายเดือนก่อน

    what is the best way to create a user logout route? Great job!!! Cumps

  • @berkaycirak
    @berkaycirak ปีที่แล้ว +1

    Hi, thanks to that next api routes, is there any need to build a backend service ? I mean, instead of building a backend service with java spring, can I use that next rest api creations ?

    • @codewithantonio
      @codewithantonio  ปีที่แล้ว

      Hey so this tutorial is a separate backend using Node, Next is more of a framework where you would keep both your backend and frontend combined. If you want a separate backend like in Spring then maybe Next would not be the best choice, but rather some other React template which is not a framework and only compiles React

  • @awesomeguy6427
    @awesomeguy6427 ปีที่แล้ว +4

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

    • @codewithantonio
      @codewithantonio  ปีที่แล้ว

      Thanks for the suggestion! I will look into it!

  • @rima-t
    @rima-t 10 หลายเดือนก่อน

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

  • @evangelinemmayie6116
    @evangelinemmayie6116 10 หลายเดือนก่อน

    Hi please is this video alright for beginners in nodejs and backend development in general?

  • @clintcode9449
    @clintcode9449 10 หลายเดือนก่อน

    if finished, can it be deployed right away or you have to do some configuration?

  • @juanantoniovivaldy
    @juanantoniovivaldy 9 หลายเดือนก่อน +1

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

  • @IngPedroAraujo
    @IngPedroAraujo 8 หลายเดือนก่อน +1

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

    • @jasonterry9343
      @jasonterry9343 5 หลายเดือนก่อน

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