Project setup

Before you connect to the database, make sure you have a basic Express project set up. If you need a reminder from Module 1:

  • Create a new project directory.
  • Run npm init -y to create a package.json.
  • Install Express, cors, TypeScript and the relevant type packages.
  • Add "type": "module" to package.json for ES modules.
  • Add the dev script in package.json.
What is mysql2?

The mysql2 library is a Node.js package that lets your Express server connect to and communicate with MySQL databases. It handles the networking and protocol details so you can focus on writing your API logic.

Installing mysql2

In your Express project directory, install mysql2 and dotenv:

npm install mysql2 dotenv
Tags: