{"id":30802,"date":"2024-08-10T08:09:43","date_gmt":"2024-08-10T16:09:43","guid":{"rendered":"https:\/\/alexrusin.com\/?p=30802"},"modified":"2024-08-11T07:49:49","modified_gmt":"2024-08-11T15:49:49","slug":"how-to-integrate-sequelize-with-typescript-in-node-js-project","status":"publish","type":"post","link":"https:\/\/blog.alexrusin.com\/how-to-integrate-sequelize-with-typescript-in-node-js-project\/","title":{"rendered":"How to Integrate Sequelize with Typescript in Node.js Project"},"content":{"rendered":"\n

In my experience, many Node.js projects require access to a database. My go-to ORM (Object-Relational Mapper) for these tasks is Sequelize. In this blog post, I’ll guide you through the process of adding a MySQL database using Sequelize with Typescript in your Node.js project.<\/p>\n\n\n\n

Step 1: Setting Up MySQL with Docker<\/h2>\n\n\n\n

To start, you’ll need to set up a MySQL instance using Docker. Here’s how you can do it:<\/p>\n\n\n\n

    \n
  1. Open your browser and search for “Docker MySQL.” The first result should be the MySQL official Docker image.<\/li>\n\n\n\n
  2. Copy the Docker command to start the MySQL container.<\/li>\n\n\n\n
  3. Open your VS Code and paste the command into your terminal. Make sure to modify the container name and port settings: <\/li>\n<\/ol>\n\n\n
    \ndocker run --name mysql-db -e MYSQL_ROOT_PASSWORD=secret -p 3306:3306 -d mysql:latest\n<\/pre><\/div>\n\n\n
      \n
    1. Run the command. If you don’t have the MySQL image, Docker will automatically download it and start the container.<\/li>\n<\/ol>\n\n\n\n

      Step 2: Connecting to MySQL Using TablePlus<\/h2>\n\n\n\n

      Next, you’ll want to connect to your MySQL instance using TablePlus or a similar database management tool:<\/p>\n\n\n\n

        \n
      1. Open TablePlus and configure a new connection:\n