Member-only story
Getting Started with Sequelize in Node.js: A Step-by-Step Tutorial
Sequelize is a powerful ORM (Object-Relational Mapping) for Node.js that makes it easy to work with SQL databases like MySQL, PostgreSQL, SQLite, and Microsoft SQL Server. In this tutorial, we’ll walk through the steps to get started with Sequelize, from installation to defining models and running basic queries.
Not a Medium member? Read this article here
Step 1: Setting Up Your Project
First, let’s set up a new Node.js project.
- Initialize a Node.js Project:
Open your terminal and run the following commands to create a new directory and initialize a Node.js project:
mkdir sequelize-tutorial
cd sequelize-tutorial
npm init -y
2. Install Sequelize and a Database Driver:
Next, you’ll need to install Sequelize and the appropriate database driver for your chosen database. In this example, we’ll use MySQL, but you can choose any supported database.
npm install sequelize mysql2
If you’re using PostgreSQL, SQLite, or another database, replace mysql2
with the appropriate driver, such as pg
for PostgreSQL or sqlite3
for SQLite.