No video

Build RESTful APIs with Node.js express and MySQL | Authentication with JWT | In one Video

  Рет қаралды 199,884

Technical Babaji

Technical Babaji

Күн бұрын

Get the video source code : github.com/Tar...
Lets try to build a RESTful API to do CRUD operation on a MySQL database. A lot of developers wants to map REST to CRUD directly, because REST over HTTP provides GET PUT POST and DELETE, while CRUD provides CREATE RETRIEVE UPDATE DELETE. It’s natural to want to map the REST provisions directly to CRUD operations and we’re gonna try that.
=============================================
For any Business enquiry contact us
Gmail :- tarique.rkl@gmail.com
WhatsApp :- +917978073704 (for only business query)
=============================================
How are we going to do?
Building APIs with nodeJS is dead simple, especially when you’re a beginner, you can opt for expressJS to build your very first API sets.
Lets kick start!
I’ve used express-generator to generate a directory called apidemo. In my mysql server, I have a database called “test”. I’m establishing connection between node and my mysql database.
A. Installing mysql
B. Connecting to database
Step 1 of my mission is done, and I’m going to get into renaming route to make my API naming conventions look professional.
I’m renaming the routing convention of the highlighted line to “/api/users”.
I’m tweaking my user_service.js to fetch result from the database(Retrieve in CRUD). We’ve already established connection to DB in the previous step, in this step we’ll use GET method to get the list of users via the API that we’re constructing.
Let’s use POSTMAN to check the API that we’ve just built.
Now that we’ve made the basic skeleton of the API, let’s complete the structure properly. When we have no server errors, the API is going to work, but when we have some issue, the end-user of the API will have no clue about what went wrong! Here’s how he will get idea about what went wrong!
Lets check the error response! I’m renaming the “users ”table in my database to “members”.
Simple route for GETing results from a database is done!
NodeJS is simple yet powerful programming boon for API making. UBER, IBM, PayPal, NETFLIX and MICROSOFT relies on nodeJS for constructing APIs. If you’re good at front-end javascript development, go ahead with learning the back-end javascript!
#nodejs #mysql #api

Пікірлер: 254
@TechnicalBabaji1
@TechnicalBabaji1 3 жыл бұрын
Joi my WhatsApp group for query and help chat.whatsapp.com/GsuvlYqwHFT0E27pUikeY0
@rohitsridhar2257
@rohitsridhar2257 2 жыл бұрын
This group is full Can't join
@anujupadhyay10
@anujupadhyay10 3 жыл бұрын
i). 00:00 Introduction ii). 05:30 Start the server iii). 11:07 Connect to the database iv). 20:18 Secure the environment v). 21:36 Create API/service 'createUser' vi). 34:44 Create other services vii). 38:23 Define controllers for the services vii). 43:57 Define routers viii). 51:45 Create login API ix). 1:01:02 Middle-ware for token validation Thanks for the tutorial. Very informative!
@poojapoojitha9114
@poojapoojitha9114 Жыл бұрын
why didn't you use sequelize??
@martinmtandi335
@martinmtandi335 4 жыл бұрын
This is exactly what i am looking for. You sir, just saved my job. Thank you for making this tutorial. May you kindly make a playlist of how to write apis using Mqsl with Nodejs.
@instant-code
@instant-code 4 жыл бұрын
great brooo...👌👌👌 1 week se dhundh raha tha finally i got you are best bro....
@typesoffun
@typesoffun 4 жыл бұрын
you are awesome brother.i have no word for you to thankyou.i cant explain my happiness..you did really good job..this is the thing which i want..like in professional way..thankyou man thankyou...please make more video in node js in professional way..
@hakimmakhtour1059
@hakimmakhtour1059 4 жыл бұрын
Thanks a lot Bro, i'm a student and it was one of the bests tutorials i've ever seen ! Can you please do a tuto for how to use it with VueJS or ReactJS ?
@antonykithaka217
@antonykithaka217 4 жыл бұрын
Hey this is the best tutorial I have seen so far, thanks
@SrinubabuRavilla
@SrinubabuRavilla 2 жыл бұрын
You made my day! clear and neat explanation. Thank you.
@sandeepsethy8943
@sandeepsethy8943 4 жыл бұрын
got to know so many small points which i missed in my project . Thanx bro
@anamikaahmed4887
@anamikaahmed4887 2 жыл бұрын
Best video on this topic so far!
@anilmittal2964
@anilmittal2964 4 жыл бұрын
Very informative and practical. The explanation and sequence of tutorial is too good and easy to understand. Thanks
@muradsalameh5294
@muradsalameh5294 2 жыл бұрын
Thank you so much! I thoroughly enjoyed this tutorial. Would you be able to make a tutorial on how to connect this to the frontend of the application?
@caiogabriel4098
@caiogabriel4098 2 жыл бұрын
Brazil here. Thanks for this stuff.
@bhnienhuis
@bhnienhuis 3 жыл бұрын
Thank you, great! This was what I needed to secure the backend for my Vue app 🙂
@AshokPatel-gd9ec
@AshokPatel-gd9ec 10 ай бұрын
This video is really too specific and much helpful for me, Thanks bro
@timuryalta
@timuryalta 4 жыл бұрын
Truly an amazing tutorial. So helpful omg
@AfzaishNaveed
@AfzaishNaveed 5 ай бұрын
very good tutorial point to point no time wasting thanks sir
@jehuzubiri
@jehuzubiri 2 ай бұрын
This helps me a lot. Please create more video sir
@suriyaprakash5609
@suriyaprakash5609 2 жыл бұрын
great work bro
@gilmcglory3748
@gilmcglory3748 4 жыл бұрын
This is a great tutorial contain so much. I learned a lot that will be very useful for me. Thanks so much!
@cateusmdeepblue7824
@cateusmdeepblue7824 4 жыл бұрын
Thank you. I am new to this and this cleared a lot of confusion. 👍
@TheCodingOdyssey
@TheCodingOdyssey 4 жыл бұрын
This was really hepful mate! Okay? Fine!
@tolkien11
@tolkien11 3 жыл бұрын
hahaha
@shreyashkarandikar
@shreyashkarandikar 4 жыл бұрын
Thanks for the video now I will use these api in my android application
@d-landjs
@d-landjs 4 жыл бұрын
Thanks, awesome tutorial!!! It would be great if you created another video with good practices for creating restfull apis!
@laurentguillou7134
@laurentguillou7134 4 жыл бұрын
Thanks a lot, I transform the API to connect a SQL Server database with succes.
@maddynewera
@maddynewera 3 жыл бұрын
wow.. Awesome tutorial bro... now i learned express and node. Thanks a lot.
@popov.artem1205
@popov.artem1205 4 жыл бұрын
Excellent tutorial! Thanks for your spended time!
@nirajshrestha9606
@nirajshrestha9606 3 жыл бұрын
The tutorial was very helpful, thank you so much
@MdSalman-kw8ng
@MdSalman-kw8ng 3 жыл бұрын
*****NEED HELP***** at 25:00, everything works fine if I use string values in the insert statement instead of (?,?,?,?,?,?) and data array but when I insert the (?,?,?,?,?,?) and data array I get an error stating code: 'ER_BAD_NULL_ERROR', errno: 1048, sqlMessage: "Column 'firstName' cannot be null", sqlState: '23000', index: 0, sql: 'INSERT INTO users(firstName, lastName, gender, email, password, number) VALUES(NULL,NULL,NULL,NULL,NULL,NULL)'
@manojparmar4905
@manojparmar4905 4 жыл бұрын
Thanks Technical Babaji. It's really very well explained.
@dreamvallyhasan4807
@dreamvallyhasan4807 Жыл бұрын
You are just awesome..... Amazing tutorial..... Thanks from the bottom of my heart
@mallikatarannum9033
@mallikatarannum9033 4 жыл бұрын
Thanks re.. Kaam aayega bohot ye. :)
@fluttterdev1k
@fluttterdev1k 11 ай бұрын
the best tutorial ,thanks a lot bro, just keep going to do useful tutorial like this .
@rupeshjaisawar5314
@rupeshjaisawar5314 3 жыл бұрын
Best and simple explanation make more videos like this
@teckieboomer
@teckieboomer 3 жыл бұрын
Great video and just what I was looking for. One question though, fsevents appears to be one of the package dependencies but npm will not install that package as it only works for Mac OS. Do you know if a workaround or alternate package for Windows dev environments?
@phahladiramoja3845
@phahladiramoja3845 10 ай бұрын
Thank you sir. Please continue on!
@sridhargn1559
@sridhargn1559 3 жыл бұрын
Really Awesome. Your work so much Appreciated...
@jmowahid
@jmowahid 4 жыл бұрын
Exactly what I needed. Thank you
@Spmdiamond
@Spmdiamond 2 жыл бұрын
Love you bro I have done with signup also❤️❤️
@ManeelxAkosAdor
@ManeelxAkosAdor 4 жыл бұрын
Nice video, I learned a lot. I have a question, if you require a valid jsontoken to create a user, and you only provide this token only when you login, how do the users can sign up (create its user) in the first place? Thanks in advance.
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
Yes you have pointed out very good question. Let me tell you my friends I was trying to keep this video as simple as possible so everyone can atleast get basic idea how to make rest apis but in real use there will a lot of checkpoint and bypass condition
@shivuvk1899
@shivuvk1899 Жыл бұрын
Thank you..Super explation and this video very helpful for me🤩😍
@sujataadam
@sujataadam 2 жыл бұрын
hi, I am facing one problem, when i am using "getUsers" , I am getting "res.json is not a function" error, why this happens, please help me.
@christopher6752
@christopher6752 4 жыл бұрын
This video is so awesome dude
@leroyjeslyn6570
@leroyjeslyn6570 2 жыл бұрын
To anyone who might need it If you get an error on post func - creating user Try changing the postman body type form text to JSON
@jayvele1804
@jayvele1804 Жыл бұрын
god
@leroyjeslyn6570
@leroyjeslyn6570 Жыл бұрын
@@jayvele1804 Glad I could help
@umeshanirmani
@umeshanirmani 2 жыл бұрын
Excellent tutorial! Thank you
@AD-Zain
@AD-Zain 4 жыл бұрын
Thanks for nice video. But the problem Sql and NodeJs is, how to handle one-many-table without repeating the data like [{id:1, images:[image1, image3, ...]}]
@PURESOUL-qv8xm
@PURESOUL-qv8xm Жыл бұрын
facing the issue in bcrypt,when i execute post "Error: data and salt arguments required    at hashSync" like error is showing... After change the key and value of header in postman also showing same error.
@krishnaupadhyay4265
@krishnaupadhyay4265 Жыл бұрын
this error occurs occurs in hashSync() check if body.password is getting undefined or null instead of this ---> body.password = hashSync(body.password, salt); write this --> if(body.password){ body.password = hashSync(body.password, salt); } in updateUser, under user.controller.js file
@rishabhdubey6674
@rishabhdubey6674 2 жыл бұрын
Hello sir, we good video to understand the whole process....Thank for it, but I get stuck in hashing part, when I am using comparesync it is returning false each time.
@channuyatnur2230
@channuyatnur2230 2 жыл бұрын
very clear explanation with step wise.
@Radhe17rohit
@Radhe17rohit 4 жыл бұрын
Great tutorial. I have one question why use PATCH instead of PUT for update action ?
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
Anything you can use its upto you. There is no restriction
@Radhe17rohit
@Radhe17rohit 4 жыл бұрын
@@TechnicalBabaji1 Thanks & if i am integrating this API with react frontend then how to send the token from there ?
@saidosmanhussein2820
@saidosmanhussein2820 Жыл бұрын
Worth to watch. Thanks.
@user-sy4mp8hq6i
@user-sy4mp8hq6i 2 жыл бұрын
This is a very good tutorial! Can you please also do the same tutorial again but with Postgresql instead of MySQL (including Vue js if possible)?
@facundoorlando4942
@facundoorlando4942 3 жыл бұрын
Hi, thank you for this awesome walktrough! I've a question... When I submit my form in react, the server show me 'Error: data and salt arguments required ' ... How could I solved this problem? Sending the JSON from postman, it works well...
@sanjyotvelip6462
@sanjyotvelip6462 2 жыл бұрын
Even I'm getting the same error.how to solve this?
@mrays2729
@mrays2729 Жыл бұрын
@@sanjyotvelip6462 while updating i am gettingsame error
@ibrahimmansoor5286
@ibrahimmansoor5286 7 ай бұрын
Freaking legend right here!
@alexandrudomente7222
@alexandrudomente7222 3 жыл бұрын
Very nice tutorial !!!! good job
@UtsavBaral007
@UtsavBaral007 4 жыл бұрын
I don't get it, How can you login without adding an user? The user first needs to register then login, isn't it? How am I supposed to login if I am not registered?! passing bearer token while registering doesn't make any sense.
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
You are right. I was just trying to show the concept. In normal scenario add user will be signup or registration there we will not add token validation
@imtiger92
@imtiger92 3 жыл бұрын
Exsume Babaji, can I ask you an example on making multiple queries? Because in my example I need to insert some rows in an other table in order to keep the consistency of the foreign key. Thank you in advace, your videos are very great.
@testnameone806
@testnameone806 Жыл бұрын
I am finding the patch/ update user service result is not an array, so results[0] returns undefined, simple returning results seems to work. Same with deleteUser
@TechnicalBabaji1
@TechnicalBabaji1 Жыл бұрын
May be they have updated the library 📚
@codetoanbug2053
@codetoanbug2053 4 жыл бұрын
thanks for sharing. good video!
@Spmdiamond
@Spmdiamond 2 жыл бұрын
Hii i am facing error 1:00:05 after solving not working
@parampatel7506
@parampatel7506 2 жыл бұрын
Perfect explanation
@goncaloribeiro808
@goncaloribeiro808 3 жыл бұрын
Could you, please, explain the "null" first parameter of the callback functions on the services files? Thanks
@TechnicalBabaji1
@TechnicalBabaji1 3 жыл бұрын
First parameter is reserved for errors if its null means no error we could check second parameter which is reserved for results
@sandy359sandy
@sandy359sandy 3 жыл бұрын
Great topic 👍
@onieltelies4953
@onieltelies4953 3 жыл бұрын
Hi...thanks buddy...its so much helpful..😊😊
@mayankrajput2102
@mayankrajput2102 3 жыл бұрын
Thanks, well done my friend
@mirandamon2533
@mirandamon2533 4 жыл бұрын
greate video :D one question please... Should I put conectionLimit parameter on pool configuration? What happens if I do not put this parameter? Thanks for your attention :D
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
If you will not provide it will take default value which is 10
@mirandamon2533
@mirandamon2533 4 жыл бұрын
Technical Babaji if I put my project on production, 5000 limit conection number is good or is it so expensive?
@aakashsharma7653
@aakashsharma7653 Жыл бұрын
please add your video also like trending now, else i have sleeped few times in this video
@hafizadeel493
@hafizadeel493 4 жыл бұрын
Thanks, this tutorial help me a lot
@ManishSankari
@ManishSankari 2 жыл бұрын
Thanks but when I post or get it says... "success": 0, "message": "Access Denied! Unauthorized User"
@laurentguillou7134
@laurentguillou7134 4 жыл бұрын
Hello, when I have a database error (Violation of UNIQUE KEY constraint for exemple), the API crash with the Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client. Do you know why?
@md.rakibuddinrana3765
@md.rakibuddinrana3765 3 жыл бұрын
thanks for this awesome tutorial bro
@narebinhaa
@narebinhaa 2 жыл бұрын
Thank you!! Very helpfull!
@prasannas439
@prasannas439 6 ай бұрын
I getting error Database connection error
@umairamjadbutt9752
@umairamjadbutt9752 4 жыл бұрын
I am not getting any response in my postman however data is being posted my database...Any specific reason for this ? not getting any response in my postman
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
I can't say what is the root cause because anything you will miss then request will continue without any response. Please debug the api
@phalsopha5239
@phalsopha5239 4 жыл бұрын
Thank you very much sir .
@trungducnguyen419
@trungducnguyen419 3 жыл бұрын
Thanks for the tutorial 😁
@shyiramberejoseph9406
@shyiramberejoseph9406 4 жыл бұрын
You did well! thank so much
@atithipatel9154
@atithipatel9154 3 жыл бұрын
Error Cannot POST /api/users/ Hello why am I getting this kind of error when I post req on postman?
@Snehanomics
@Snehanomics 2 жыл бұрын
you installed node js beforehand?
@webfreelancershub6718
@webfreelancershub6718 Жыл бұрын
Thank You soo much sir.
@ericmwangi9547
@ericmwangi9547 4 жыл бұрын
I used postgres in my case. my jsontoken not showing .It say invalid email or password even though my email and password is exactly the same. My password data type is character varying : 255 length
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
I need to your code then only I can say that
@ericmwangi9547
@ericmwangi9547 4 жыл бұрын
@@TechnicalBabaji1 here is a link to the code: github.com/ricomwas/node-project
@ericmwangi9547
@ericmwangi9547 4 жыл бұрын
I was able to figure it out, I added the rows[0] on the callBack results.
@sathithyayogi99
@sathithyayogi99 3 жыл бұрын
wow super video
@usharamagiri1005
@usharamagiri1005 3 жыл бұрын
After defining controller for the services and we will post in the postman then i am getting data and salt arguments required what to do with this error
@santoshkumar-ke5ug
@santoshkumar-ke5ug 2 жыл бұрын
CompareSync always give False result. body password and the password comes from datbase are same but result is false. Please help.
@nxnnan8019
@nxnnan8019 4 жыл бұрын
Thank you for this video,So I want to know how to create logout
@vikramkumar-jy9tz
@vikramkumar-jy9tz 3 жыл бұрын
Tutorial is awesome,buti get the error while testing the post method ERROR: data and salt argument required. Pls guide to solve this
@FernandoSecchi
@FernandoSecchi 3 жыл бұрын
I have the same error...
@iamcode9264
@iamcode9264 4 жыл бұрын
i got a message ('Route.post() requires a callback function but got a [object Object]') when i try to create verify token(check token) used it in my router
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
I understand your problem you are not passing function but I have to see where this is coming
@feminiscence
@feminiscence 4 жыл бұрын
change next(decoded.result) to next() in TokenValidation.js
@pranav3406
@pranav3406 5 ай бұрын
why i m getting error of (data and salt arguments required )
@joaquinpolonuer4491
@joaquinpolonuer4491 4 жыл бұрын
Thank you so much
@primerevan8403
@primerevan8403 3 жыл бұрын
Are we using nodejs orm here?? If not I would watch I want to run raw queries inside from nodejs and want that. If you have any resources related to that pls help
@aumradia5397
@aumradia5397 2 жыл бұрын
I am using mysql workbench and every thing is going alright but i am not able to conect to database...........? can any one pleasehelp me?
@wenkwonk1383
@wenkwonk1383 3 ай бұрын
Is this code still working to the current version of the dependencies?
@indanasandeep2066
@indanasandeep2066 3 жыл бұрын
got this error TypeError: Assignment to constant variable. and this due to reassignment of const variable token but in your case how did you handle
@nikhilbarve7520
@nikhilbarve7520 Жыл бұрын
Type Error : cannot read properties of undefined (reading ' gen_salt_sync.
@nikhilbarve7520
@nikhilbarve7520 Жыл бұрын
Please get solutions
@kavyakavya1788
@kavyakavya1788 Жыл бұрын
while deleting the record i'm getting the status :0 and record not found but the record is deleted in Database , if anyone know why it is coming can you please help me and also how to use delete api with body also tell me please
@LORDFARQUAADIUS
@LORDFARQUAADIUS 3 жыл бұрын
Thanks for the code!
@StarDigital79
@StarDigital79 4 жыл бұрын
Thanks for sharing
@stuffsloader2315
@stuffsloader2315 Жыл бұрын
in 33:50 Min When I post a value The Error Has Been Showing Like Error: the gensaltSync hashSync Need To Be Required
@nithyajegan1990
@nithyajegan1990 3 жыл бұрын
sir when i run terminal ill get This error "TypeError:create pool is not a function" i dont no how to solve please help
@abrambagusjanitra1794
@abrambagusjanitra1794 4 жыл бұрын
my jsontoken not showing .It say invalid email or password even tough my email and password is exactly the same, can you hep me?
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
This happen when your password doesn't match. Actually what happened you may have taken password field as varchar(20) just for example. But hash password length will be greater then 20 than in this case it will ignore rest character and save upto 20 char and than at the time of login it is getting 20 character hash password which is not the correct one.. Suggestion take password field as text or increase varchar (100) in MySQL
@abrambagusjanitra1794
@abrambagusjanitra1794 4 жыл бұрын
@@TechnicalBabaji1 ok thank you very much, but when i deleted my data it said record not found even tough my id is invalid and why you didn't use await function?
@TechnicalBabaji1
@TechnicalBabaji1 4 жыл бұрын
@@abrambagusjanitra1794 because we are checking rowCount. And when we don't have any record its getting 0 zero which is equal to false and you can see I have given that message in false condition you can handle and give any message according to you
@abrambagusjanitra1794
@abrambagusjanitra1794 4 жыл бұрын
ok thank you very much
@feqmoreno
@feqmoreno 4 жыл бұрын
@@TechnicalBabaji1 Thanks!! I was like 1 hour without finding the error and you saved me, love your channel, keep going!
winston logger | Log into MongoDB | File | Console | nodejs tutorial
10:43
The Right Way To Build REST APIs
10:07
Awesome
Рет қаралды 96 М.
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 86 МЛН
Nurse's Mission: Bringing Joy to Young Lives #shorts
00:17
Fabiosa Stories
Рет қаралды 5 МЛН
When you discover a family secret
00:59
im_siowei
Рет қаралды 23 МЛН
ROLLING DOWN
00:20
Natan por Aí
Рет қаралды 11 МЛН
MySQL Node.js Express
28:03
Sam Meech-Ward
Рет қаралды 175 М.
JWT Authentication with Node Crash Course
1:29:11
Laith Academy
Рет қаралды 51 М.
How to build a REST API with Node js & Express
58:40
Programming with Mosh
Рет қаралды 1,7 МЛН
Wait... PostgreSQL can do WHAT?
20:33
The Art Of The Terminal
Рет қаралды 193 М.
Backend web development - a complete overview
12:58
SuperSimpleDev
Рет қаралды 1,7 МЛН
女孩妒忌小丑女? #小丑#shorts
00:34
好人小丑
Рет қаралды 86 МЛН