Harry Potter API with Node/Express and PlanetScale

This is Node/Express project for a Harry Potter API with data stored in a PlanetScale MySQL database.

📖Blog featuring this repo

📺 YouTube Tutorial

How to Use

Clone the repository.

git clone https://github.com/jamesqquick/node-express-planetscale-and-harry-potter

Then, install the dependencies.

npm install

Option 1: Manual database setup

Then, copy the .env.example file into a .env file and populate the following properties.

  • DB_USER
  • DB_PASSWORD
  • DB_HOST
  • DB_DATABASE

If you need a MySQL database to work with, you can quickly set one up in PlanetScale. After you create your database, you can create a new password to get the necessary credentials for your environment variables.

Next, run the seed.js script to create your tables and populate them with Harry Potter data.

npm run seed

Option 2: Automated database and connection setup

If you like to automatically create a PlanetScale database, seed it and configure the connectionn string in one step, execute the following command and follow the instructions on screen:

cd .pscale/cli-helper-scripts
./create-database-and-seed.sh

Final step

Lastly, run the application.

npm run dev