Node to MySQL.
I spent all of this week watching videos to learn how to access MySQL via Node. Looked at 3 videos, and this one by Nsquared Coding seemed to be the best. For some reason with the other videos I tried following along and got mostly permissions errors when I tried to connect to the local server using JavaScript commands. The Nsquared Coding one not only had complete instructions for a full stack project, but it was a little different in that it used XAMPP to connect to the MySQL port and make the database.
I still ran into a lot of errors along the way. I think one big issue was that MySQL was not installed correctly. I uninstalled it and checked to see if my web app would still work, and it didn’t. I learned that the Node module mysql
is just a driver, it’s not actually MySQL. When I reinstalled MySQL, MySQL Server would not install, and I think I recall that happening the last time I installed MySQL some weeks ago. Someone online found a workaround to install Server by itself first, then go back and install the rest of the suite, and that worked.
The other issue was with Live Server, a plugin on Visual Studio Code (something else I learned about – it’s pretty handy, it autocompletes in several different languages and has a lot of plugins). For some reason my web app was not updating as I made changes the way it was in the video. I never figured out why. I got a little over halfway through the video before I realized this. I went back and viewed certain parts of the video again. Then I realized, the final files are in a Github repository, so I went there and compared the code with what I had. Everything looked fine. I tried viewing the source and the console and fixing errors. Didn’t work.
So my goal for today was to figure out that error and then finish off the video but it was becoming hopeless… so I just cloned the repository, moved my .env file and node_modules directory, and what do you know, it worked! At some point when I was troubleshooting I ended up turning off my firewall (at least for the local network). Turned it back on and it still works, it just asks for permission to do everything. I now see that to get it to work I have to open client\index.html
with Live Server in VS Code, open XAMPP and start both the Apache and MySQL servers (servers or ports?), open a terminal in VS Code and type nodemon server\app
(I found out nodemon
is a Node module that lets you reload a web app as you make changes without having to stop and restart the local server).
Also learned dotenv
is a Node module that lets you create a .env file with all of your sensitive information that you can put in the .gitignore if you upload your project. Another module, cors
, was used, and I’m not sure what that does. Also, express
was a big one but I still don’t quite understand what it does, either.
I guess I did cheat a little but at least now I have a product that works. Obviously what I’d like to do next is start modifying it for my particular project. I’d also like to read about what some of the JavaScript commands are doing, and I plan to continue to use the video as a reference. It’s nice to know that if I break it I can always clone the repository again and start over.
Finally, once I’ve learned more I’d like to go back to the other videos that didn’t use XAMPP to create the database and try to incorporate some more SQL commands. After all, this project started as a way for me to learn SQL. I also wanted to learn React, that wasn’t used in the video. Maybe once I have what I want I can go back to try to make the front end prettier, I think that’s what React does.