Node.js + MySQL CRUD - GET,POST,PUT and DELETE
HTML-код
- Опубликовано: 14 окт 2024
- MySQL CRUD Operations in Node.js application.
Updated video is here : bit.ly/3MwUcwS
In this tutorial, we'll discuss how to implement crud operation insert update delete and view all in node.js with MySQL database.
Content Discussed :
How to Connect MySQL DB from Node.js
Execute MySQL Query From Node.js
Use of MySQL Store Procedure in Node.js.
📂 GitHub Repository
► goo.gl/3JKBNM
💖 Buy me a Coffee
➤ bit.ly/3L36ut4 (PayPal)
➤ bit.ly/3VF0iPT (Razorpay)
🌀 Related Videos
goo.gl/T9Nb8r : Angular CRUD with Web API
goo.gl/wp17ta : Angular User Registration With Web API
goo.gl/4gDFfC : Angular Login Logout With Web API
goo.gl/ySUFf8 : Similar Mvc Tutorials
🔗 Find me in
Udemy : bit.ly/3RtyQSB
Facebook : / codaffection
GitHub : github.com/cod...
Discord : / discord
Twitter : / codaffection
#NodeJS #MySql #CodAffection
goo.gl/RFY5C2 : Subscribe to CodAffection
goo.gl/bPcyXW : Buy me a Coffee
How can using MySQL and MS-SQL on the same machine
Hi, have you ever tried building the query into a middleware? I'm having issues exporting my response. Any tips?
WHAT IS THIS ACCENT?
Man, very thanks for this video
[04:40] : index.js
[07:46] : express
[18:24] : Insert an employees (Store procedure)
[26:05] : Update an employees
At 11:10 I felt a CATHARTIC feeling, thank you mate!!
That was the point when I understood the whole meaning of "API" and "backend". :)
I started my learning path with courses on frontend, how to create simple webpages (HTML, CSS, JavaScript basics),
then I learned the SQL queries of MS SQL and MySQL,
and now I could connect the two with your help, thanks a lot!!
Good video. Just to make life easier at the start when you're creating a package.json file. If you type "npm init --yes", a file will be created without asking you any questions.
it can also work with npm init -y ..
awesome, without --yes it was giving error module not found. thanks for help :)
Thanks for the info.
Wow...simply wow. Took a bit for me to get everything installed and to work out my syntax errors but your tutorial is flawless. Thanks!
Amazing thank you , I'm used to use mysql for my project and when i saw for node everyone use mongodb , i learn mongodb but I'm really happy to see i tutorial for node and mysql so thank you :)
Hey yukina! Do you know of a video like this, but with mongodb instead of MySQL ? That would be really helpful! Thanks :)
For anyone looking to copy and paste some SQL statements with some sample data for insert and just wanted to save some typing:
use EmployeeDB;
create table `employee` (
`EmpID` int(11) not null auto_increment,
`Name` varchar(45) default null,
`EmpCode` varchar(45) default null,
`Salary` int(11) default null,
primary key (`EmpID`)
) engine=InnoDB auto_increment=0 default charset=utf8mb4;
select * from employee;
lock tables `employee` write;
insert into `employee` values (1, 'Tommy Eatsheet', 'EMP90', 265400), (2, 'Jess Fukenson', 'EMP92', 50000),(3, 'Bob Knobhead', 'EMP95', 10000),(4, 'Dick knogginson', 'EMP96', 90000);
Thank you.
i was literally searching this in comments ,thankyou somuch.
Thank you so much, I was searching for this from 7-8 hours but nothing found , Now I have done it in one try after this tutorial. Again thanks
Glad you found this helpful.
Thanks man! It really helped... I was searching on the internet since a long...finally found something useful...Nice explanation.
Thanks you i was looking for this entire RUclips and here i get my solution love from india😇
Congrats, amazing tutorial, I imagined Node.js was a monster.
thank you so much, i was searching it for 1 week finally i got from this video it was excellent
Glad to hear that
Thanks sir I watched lots of video but that didn't worked for me but your video worked properly for thanks for such a great tutorial
Glad to hear that
Thankyou so much again for such a wonderful video that make me understand Node jS API and I can say I know Node js.
Awesome tutorial!
Just had one question regarding the mysqlconnection.
I noticed that you never actively closed your connection to the database. Will that cause issues in production, or are there underlying features within the packages used that help manage the connections as clients connect to your application?
This is exactly what I was looking for. Thanks !
This was perfect thanks a lot. Just in case someone is using this today or in the near future, I had an error on workbench
I changed the last line of code to this
ENGINE=iNNOdb AUTO_INCREMENT=0 DEFAULT CHARSET=utf8
and it worked just fine
It was the only issue I had
TY
Thanks man you saved me
it is very helpful and easy way to understand api thanks a lot
This is superb guidance tutorial for beginners
Glad you think so!
excelent, Brazil here, thx for help!
Great tutorial
Exactly what I needed, Thanks a lot :) Just a tip for those who are facing problem in inserting data to the database table - make EmpID AUTO_INCREMENT
but in my code auto increment is not working I don't know why
Very nicely explained Thank you!
love your tuts..... plz make a tutorial on "WPF login(hashed) MVVM and EF7 CRUD application with online mysql database "
Thank you very much for the tutorial. It is the great tutorial I have met so far.
It was the best tutorial I ever watched about GET,POST,PUT and DELETE
Started just in the beginning, I know that this is what I was looking for. Thanks
glad it helped.
Thank you bro. You make easy to understand.
How to write procedure in mysql(phpmyadmin)
thankyou, may i ask what is difference between put and post
Great!!!! easy explaination and simple script usage
Hello! Good tutorial! If you don't mind, could you please advise me, how to post query results to normal address, without port number. Seemingly i cannot post result to the page.
17:28 Did you mentioned 'ForceMan'? Why did you use it?
Very Nice, Very Easy
thank you so much, amazing tutorial here!
very helpful tutorial.
@raddy 's tutorial is awesome
if i refactor my code into multiple files eg. routes etc do i need to create mysqlConnection object for every page? please reply thank in advance :)
somebody plz tell how to connect this nodejs to angular for crup operations plzzzzzzz
Excellent!. Concise, precise, direct and accurate. I tried mysql v8.0 initially. It threw error about authentication/authorization. Changed to mysql 5.6 and then everything went fine. Can you show how to work with mysql v8.0, the latest? Thanks.
+1
npm i mysql2 and then the following code in your index.js file const mysql = require('mysql2')
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : "&&&&"
database : 'EmployeeDB'
});
connection.connect((err) => {
if (!err)
console.log('DB connection succeded.');
else
console.log('DB connection failed
Error : ' + JSON.stringify(err, undefined, 2));
});
@@tripathi5174 thank you so much, it worked for me..
For those who get this : ER_NOT_SUPPORTED_AUTH_MODE
after doing node index.js
this is error is mentioning when you install sql server you selected"strong authentication", but you set a weak password. You need to reset strong password or need to choose legacy authentication method.
Follow these steps to choose legacy authentication method
You installed mysql server using "mysql installer"
1)open -> "mysql intsaller"
2)press reconfig mysql server
3)select left side "authentication method tab"
4)select radio button -->use legacy authentication method
5)now stop and restart the db
and it should work
thanks buddy
Nice tutorial!!
it was very helpful ,thankyou
can you tell me how can i use this to create a login feature on my HTML website using nodejs and mysqlworkbench
Thank you so much, it is help me a lot, how to display data in html table?
The table creation data:
CREATE TABLE `employee` (
`EmpId` INT(11) NOT NULL AUTO_INCREMENT,
`Name` VARCHAR(45) DEFAULT NULL,
`EmpCode` VARCHAR(45) DEFAULT NULL,
`Salary` INT(11) DEFAULT NULL,
PRIMARY KEY (`EmpId`))
ENGINE = InnoDB AUTO_INCREMENT=0;
you saved me
literally killed me with your joke 7:25
Thank you so much , very clear tutorial it really helps me !
Glad it helped!
What online cloud database do we use to migrate/deploy the mysql workbench database?
hello codeAffection can you make the same thing for nodejs+postgresql the connection,how to insert,update,delete using the post,get,put http request can you??
in 22:24 when you made a variable and called it SQL you add '@' behind each of the request data like 'set @empId = ?' I want to know why?
I can't just do the POST!
You can also use MySQL server of XAMPP
tq....exactly wat i needed ....great tutorial
Thanks for your efforts and time - Dotnet Mob, Just a small question if you have time, how we can use this node project as back-end for angular
Node.js act as back-end in MEAN stack applications with Angular(front-end).
Yes that is ok but, my interest is how to do this?
Within 1 week, I'll upload a video tutorial on this topic.
Tusi Great Ho Paa Jee,
MEAN Stack CRUD Operations : ruclips.net/video/UYh6EvpQquw/видео.html
Thank you so much brother. This is exactly what I wanted. 😁
Most welcome 😊
thank you
Thank You so much made my day :)
Thank you man, a very clear explanation!
IF U CREATE STORED PROCEDURE IN MYSQL USING XAMPP,
THEN IST LINE IS
CREATE PROCEDURE PROCEDURENAME(
PROCEDURENAME IS NOT BETWEEN ANY SEMICOLONS
AND USE DELIMETER AS //
Indian coding YTbers are carrying us through quarantine projects/assignments
love u bro
Integer display width is deprecated. You don't need it, you just need 'int'.
Why did you use stored procedure instead of normal query, is there any reason ?
sir, you didn't show how to make the model with for example sequelize?
thanks man.. what a great video.. easy and sharp... you saved my day. I appreciate your work.
Glad you found the video helpful.
Great! How to integrate API key with GET ,POST,PUT and DELETE request??
salaam,Mr.Imtiaz this is syed could u pls teach me about put and delete method in node js(REST API)
7845136318
How to you run index.js file in command prompt. Here i can not run node index.js file.
The video is very useful for me, thanks for your excellent job.
This is my Request to give me suggestion that how can I write API with MS Sql Server ....What are connections and packages ?
Thank you so much
Thank you very much sir. Excellent tutorial.
glad you found the video helpful.
Wouldn't setting multiple statements variable to true put your db at risk for query injection? Very easy tutorial to follow along with though...
very good tutorial !
Very helpful video. Thank you so much!
glad you found the video helpful.
Thanks for the gr8 video but getting following error if you can help
err {
"code": "ER_NOT_SUPPORTED_AUTH_MODE",
"errno": 1251,
"sqlMessage": "Client does not support authentication protocol requested by server; consider upgrading MySQL client",
"sqlState": "08004",
"fatal": true
found the solution after few research...
open MySQL command line client and run
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '****';
it will change authentication type to standard which will allow to connect
Good tutorial. Would have been better if you added a front-end to do the CRUD requests rather than using postman
ruclips.net/video/voDummz1gO0/видео.html
Thanks
Superb explanation Sir.
Exactly what I needed, great tutorial!
glad you found the video helpful.
Awesome 👏
how can I link the routes with a front end user interface whereby my user can fetch all the data by clicking on a button?
By API
Thank you very much for making this :)
No problem 😊, let me know if you have any suggestion for upcoming tutorial ?
I am getting the message DB connection succeded... but when passing /employees I am not seeing the table record
Same here... Found any solution?
any solution?
same here
@@junaidqureshi9376 can u get any solution on these??
hello sir pls provide information about how to download mysql and how to connect it with angular6
you can download the MySQL Workbench that's used in this video from dev.mysql.com/downloads/workbench/
You can also use MySQL server of XAMPP
where can I find that copy paste query? please let me know.
Very good video!!!!
what about if it not storedprocedure table then what will be the query???? kindly help me
Where is the front end for this app? I would like to see the end result before beginning the tutorial.
Thanks
Why do you use Stored Procedure instead of direct sql statement? And Why do you use multiple statement and create variables instead of just using EmployeeAddOrEdit(?, ?, ?, ?);
Thanks.
I chose stored procedure because it
- prevent from sql injection
- better performance due to execution plan.
I didn't get your second question.
@@CodAffection I mean, you declare variables and assign value to them, then you use those variable inside the call to EmployeeAddOrEdit(). Why don't you just use the params already inside the call to the stored procedure? It is, why do you use EmployeeAddOrEdit(@EmpID, @Name, @EmpCode, @Salary) instead of EmployeeAddOrEdit(?, ?, ?, ?) ?
it would make the code more readable.
@@CodAffection Got it. Thanks a lot
amazing video help alot , if anyone had same error as me can tell me the reason
the id is auto incremented by 2 like first element is 2 and the second is 4 etc..
NIce Tutorial. Its very helpfull to me.
Thanks for the comment.
so how do i reopen the workspace when it shows me this?
[Info - 8:26:41 PM] ESLint server stopped.
[Info - 8:26:42 PM] ESLint server running in node v10.11.0
[Info - 8:26:42 PM] ESLint server is running.
[Info - 8:26:45 PM]
Failed to load the ESLint library for the document c:\Users
w888\Desktop\project\package.json
To use ESLint please install eslint by running npm install eslint in the workspace folder project
or globally using 'npm install -g eslint'. You need to reopen the workspace after installing eslint.
If you are using yarn or pnpm instead of npm set the setting `eslint.packageManager` to either `yarn` or `pnpm`
Alternatively you can disable ESLint for the workspace folder project by executing the 'Disable ESLint' command.
[Info - 8:26:45 PM]
Failed to load the ESLint library for the document c:\Users
w888\Desktop\project\index.js
Hello Sir,very very Thanks for this awesome tutorial...Sir i beg to request u plzzz make tutorial for node js crud using angular js..waiting for ur response...
please try this : ruclips.net/video/UYh6EvpQquw/видео.html
Angular + NodeJS + Express + MongoDB (Mean Stack)
Thanks a lot for nice video tutorial
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, ...]}]
You are a awesome. your video really helpful for me. thank you ..
Thanks, let me know if you have any video suggestion related to node js.
awesome clean video I am from a Java background, this has been successfully helpful.
Glad you found the video helpful.
How to create this procedure in Ubuntu terminal??
Sir please make some more videos on restful api with express+mysql
I'm tired of trying connection node to mysql. im getting db connection failed. tried so many times but still getting an error. please help me out. And your explaination was awesome.
How would you do a PATCH request for this project
PUT and PATCH are used for updating so you could use PATCH in the same way as PUT
This was a really good tutorial for me.
However, when I perform a POST action through Postman, I get Insert only when EmpID is zero.
If I send a value other than 0 to EmpID via Json, a Success message appears but no data is stored in the DB.
Can you help?
if you send a json object with non zero id, it will try to update the record with given id. if there is no such employee nothing will happen.
better in client side app you can add validation or add validation in nodejs like if id is a non zero value then show some warning message.