How To Use MySQL with NodeJS
Hey what is up everyone, today we are looking at using MySQL and NodeJS to work with and store data in our NodeJS apps. This is a very simple tutorial aim toward programmers using Node and want to connect their app to a MySQL database instance. In this video we will build a very basic API to create and read posts from a MySQL database.
Hope you enjoy this video! Let me know by giving this video a thumbs up and subscribing for more content coming soon.
THANKS FOR 5K SUBS PEOPLE YOU ARE AMAZING NEVER SAW THIS COMING!💙
Video Links
==========
MySQL
dev.mysql.com/downloads/
NodeJS
nodejs.org/en/download/
Visual Studio Code
code.visualstudio.com/
mysql2
www.npmjs.com/package/mysql2
sequelize
sequelize.org/
GitHub Links are in the first PINNED comment!
My personal website
=================
www.thefullstackjunkie.com
Join my discord channel 🤓✌
/ discord
Timestamps
===========
00:00 Intro
00:52 Technologies walkthrough
04:00 Cloning Starter files
04:40 Folder walkthrough
07:53 MySQL Workbench Create New Database
14:00 Connecting Node with MySQL Database
18:30 Testing first SQL query from Node
21:00 Building out rest of little API
27:52 Building Post Model to use MySQL connection pool
45:11 Testing out final routes of API
47:35 Outro
Пікірлер: 116
about a year and a half ago i started learning Html , Css, Javascript, now i got hired as a React Native dev, im thanking all my learning channels. This is one of the best, keep the good work, and thanks, man!
@the_full_stack_junkie
2 жыл бұрын
Congratulations champ
@danko5678
2 жыл бұрын
inspiring
@hexparadusyoutube7428
Жыл бұрын
Any advice on how to get a remote software Job?
@historianooficialunofficia2085
Жыл бұрын
@@hexparadusyoutube7428 i just upload a profile in LinkedIn and in the third interview got the job
@hexparadusyoutube7428
Жыл бұрын
@@historianooficialunofficia2085 Is it a remote one and did you apply by 'Easy Apply' on LinkedIn or was it a regular Apply?
To be honest, I'm astonished by how well you explain everything. I'm speechless. Great work!
Literally Awesome explaination.🙌🙌
Dear my FSJ. Thank you 1.000.000.000 times. This is my first video after many try/catch in Node world. It works also for me. Incredible. Thank you very much for sharing your knowledge. Best regards, Štefan.
Thank you so much, You made the whole process seamless to follow along as I practice
I just discovered your channel, and it's fantastic. continue, and thank you
Keyboard tips are so cool man, thank you for that 😊
Amazing video, thanks sir!
Thank you. This was quite helpful. Straight forward.
Starter files: github.com/LloydJanseVanRensburg/Node-Express-starter Ending files: github.com/LloydJanseVanRensburg/Node-MySQL-Tut
@ashushimpi2163
Жыл бұрын
Thanks
Absolutely incredible tutorial. I've been a professional dev for 4 years and I'm working on migrating some legacy code. Even though I was planning on skimming to just see package use and connection details I ended up sitting through the whole thing. very well done!
Thank you sir!🥸
Thank you so much for this tutorial. You did an excellent job explaining things.
@the_full_stack_junkie
Жыл бұрын
Glad it was helpful!
This video helped me so much thank you
Thank you very much, its really helpful for my project
You are making my full stack journey amazing. Please try to upload videos frequently.
Great Content😀
thank you so much. excellent work
Thank you greetings from 🇨🇺
Thank you Sir for this wonderful Tutorial .I did not Know how to use oop concept in developing rest api . The code was just beautiful . Thank you ❣️❣️❣️
Good tutorial thank you sir
Thanks for these amazing videos. From nothing to be able to build my University project. I learned everything from your videos.
@the_full_stack_junkie
2 жыл бұрын
Awesome so glad it helped
@malikabdullah7709
2 жыл бұрын
@@the_full_stack_junkie Yes, It really helped me, even I still watch your videos when I stuck somewhere.
This channel is really a gem!! Thank you sir for all the knowledge transfer 🤩🙌
@the_full_stack_junkie
3 жыл бұрын
Thanks for your positivity really do appreciate it🙏🤓
🇲🇫 This is a beautiful, simple and clear tutorial as well as the well-established MVC architecture. Thank you very much for everything and especially good luck we will be there to follow you.
@the_full_stack_junkie
2 жыл бұрын
Thanks so much champ, very glad you found it helpful.
great video!!!!
much helpfull sir!
Thank you the video is so good
Thanks you so much I really needed a refresher :) Maybe a bigger project using mysql or an Orm would be great to follow :)
@the_full_stack_junkie
3 жыл бұрын
Will do
11k subs completed.👍👍👍
@the_full_stack_junkie
2 жыл бұрын
Thanks for the support will give you shout out in next video.
great video sir cleared all of my consfusions about promises
@the_full_stack_junkie
Жыл бұрын
Glad it helped
You are always awesome thank you mate..... Hoping to see image upload in this video....
Not gonna watch it now but I benefitted so much for the shopping cart mern tutorial video that I just wanted to drop by and leave a like and a comment ASAP :D
@the_full_stack_junkie
3 жыл бұрын
Thanks man. Just showing of the basics here nothing much just wanne show what I learned recently✌🤓 but thanks for the comment! And like
Thank you ;)
Thanks dear.
Thank You
Great tutorial if you have some experience with this from before, but very tough if you're new.
good job .. keep uploading ...
@the_full_stack_junkie
2 жыл бұрын
Thanks man Reddit Clone (React, Redux Toolkit, Node, MySQL) coming soon
Awesome video ++++++++++++ 🙂🙂
Great tutorial, thanks. Just one question. Is it not neccesarry to release / close the connection after db.execute(sql) ? Or is it handled in this case automaticly?
love
I'm also follow this kind of coding pattern from MVC. it's more maintainable. but what i'm thinking is, it may occur some memory leak issue because it just create new instance from Post model but not reuse any of instance. when we get ORM every ORM has some caching mechanism for reuse previous created instance.
Can you also add update and delete operations?
Hey please make video on mysqul series.
Question: do I need to use workbench or can I also use phpmyadmin without having to change any code? Nice video!
🌻
Awesome! I learned node and mongo thanks to you. How do you like mongodb compared to SQL?
@the_full_stack_junkie
3 жыл бұрын
MongoDB is much easier to work with in my opinion. Structuring your data is easier to understand most of the time. But again I have used and still use both. For some the one is better choice than the other. For me I would still give mongodb the lead specially when working with the rest of the JavaScript stack (MERN, MEVN, MEAN).
@edinburghrules
3 жыл бұрын
@@the_full_stack_junkie Yeah, I felt MongoDB was very intuitive, coming from frontend React and using Firebase. I see a lot more job postings for SQL however, so really appreciate you posting this video. Thanks! :D
@the_full_stack_junkie
3 жыл бұрын
Always good to know SQL its not going anywhere. Glad you found the video insightful. More videos coming soon.
Hey i want video on hooks. Please make a one video on this
please continue mongodb series 🥺🥺
Hello thank you for this wandeful tuto.But i have this error during registration: TypeError: Post is not a constructor. How can i salve this please ?
good tutorial, the volume cud be louder
i am having axios api issue in react native app, the axios api works fine in postman but not in the app, it send {} body to server.
Which Theme You Use in Vs Code Editor
SUBSCRIBED. GREAT CHANNEL, THANK YOU FOR THE AMAZING CONTENT🙌 (please if you have a change make a PRISMA & GRAPHQL tutorial, that would be awesome)
when you deploy your backend, what do you put in process.env.DB_HOST...obviously it is not localhost anymore
i wish you could turn you mic volume up, cause right now my volume is at 100%, and i can barelly hear your voice....but besides that that this is a awesome great tutorial, thank you 😎👍
@the_full_stack_junkie
3 жыл бұрын
Ooo wow thanks man will definitely turn it up next time didnt know it was to soft my bad. Glad you found it helpful
Sir, can we stop connection after connection because for aws always needs to start server. How i do it. Please give hint by syntax..where i destroy the query and how to add prod database user name and password..if u reply soon that helps me alot..and for this video realy realy awesome..
it's what i was looking for but i don't understand what we have to manually create the database and table instead of just doing it with mysql2
Bro when will e-commerce tutorials be on page
Can you do some MERN Social media app
Waiting for Nodejs with postgress 👀
wich web server can I use to node.js and mysql?
Hello! How i can use transactions?
Hello, Thank you so much for the video but just a quick question, if you are hosting your database locally would that mean your computer has to be running 24/7 If you plan on using this database for a live website?
@the_full_stack_junkie
4 ай бұрын
Yes you will need to keep you computer on
do you make model and controller for each one and one, for example users , posts, etc...
@the_full_stack_junkie
2 жыл бұрын
So the models are made to represent the schema of the table in the database. And the controllers are then made to use the models and work with the database. So you can see it as such that a controllee can be for example for each one of the entities (posts, comments, users etc). But this in not always the case you can make controller methods for different things. But the controllers job is to work with the models and do some business logic
Sir please make on one video microservices node js tutorial
@the_full_stack_junkie
3 жыл бұрын
Hey man I am not really familiar with microservices, yet. I have done one course on it but I hasn't been something I have been actively working with. Would really recoomend checking out udemy, stephan grinders course on microservices in nodejs.
please upload update api
heyy can someone help me to fix that error # - access denied for user 'root'@'localhost' (using password no)
In ur ecommerce series there is no search feature.😕
which color theme do you have for vs code?
@the_full_stack_junkie
Жыл бұрын
Cobalt
how do you the Updating part. static update(vorname, nachname, id) { let sql = `UPDATE Anbieter SET vorname = ${vorname}, nachname = ${nachname} WHERE Anbieter_id= ${id};`; return db.execute(sql); } this isn't working
@duyennt1351
2 жыл бұрын
I'm looking forward to the update. I have code but it error in postman exports.updatePostById = async (req, res, next) => { try { let { title, body } = req.body; let postId = req.params.id; let [post, _] = await Post.updatearticlebyid(postId, title, body); res.status(200).json({ post: post[0] }); } catch (error) { console.log(error); next(error); } };
34:31 That would be a very poor practice in production. You're supposed to escape the values to prevent SQL injections: VALUES (?, ?, ?) and pass the actual values into the `execute` method: await pool.execute(sql, [this.title, this.body, createdAtDate]);
@benzemamumba
2 жыл бұрын
No doubt, this is only a proof of concept buddy. No need to be pedantic about things.
everything is good but why audio is so down?
what is the dotenv module?
@the_full_stack_junkie
2 жыл бұрын
Basically helps us set env variable in our node app. Gives us access to process.env.
github link?
Some nice SQL injections if you push this code to production.
where is the git clone link ?
@the_full_stack_junkie
2 жыл бұрын
The post comment at the top.
@nallaiahkalis4224
Жыл бұрын
@@the_full_stack_junkie not there
@brickstv3156
4 ай бұрын
@@the_full_stack_junkie its not there bro
It's quite unusual to hear about NodeJS & MySQL being used together. Why are all these people using it with Mongo DB ? Just a trend ?
@the_full_stack_junkie
Жыл бұрын
Nodejs can be used with almost any db. Mongodb just has a very populate syntax which is JS like so just keeps things lookin like JS.
i can hear a mzansi accent...?....?....? ❤❤
@the_full_stack_junkie
6 ай бұрын
Fo sho 🤙🏼
The official way to pronounce MySQL is My Ess Que Ell, not My Sequel.