MySQL in Node 101: Setup and Access
Published in
8 min readFeb 16, 2020
Level: Web Developer Beginner
If you are new to the web developer world, you may be wondering what comes after the HTML and JavaScript track on w3schools. The static website project has a couple of interactive buttons and animations, but how do we display dynamic data?
This article is for you! We will cover the following:
- Setting up a local MySQL database on your laptop with Docker.
- Installing a database package into your express app.
- Setting up Database connection on startup.
- Reading from the Database when a request happens.
- Writing into the Database when a request happens.
- Part 2: what if we are using TypeScript? Or another web framework?
Step 0: The Setup
- Pick a nice Editor. I use WebStorm with Prettier enabled.
- Install Docker on your local environment. You can find a direct download link for Mac here: https://download.docker.com/mac/stable/Docker.dmg
- Is Node available? Check with running
node -v
. If you do not have Node.JS yet, check out https://github.com/nvm-sh/nvm - Is Git available? Check with running
git
in the command line. On Mac, typinggit
without it…