🟢 Node.js Intermediate

What is the Sequelize ORM in Node.js?

Why Interviewers Ask This

This tests whether you can apply Node.js knowledge to real-world scenarios. Interviewers are looking for clarity of thought and evidence that you've encountered this in production code.

Answer

Sequelize is a mature, promise-based ORM for Node.js that supports PostgreSQL, MySQL, MariaDB, SQLite, and Microsoft SQL Server. It allows you to interact with databases using JavaScript objects instead of raw SQL. Key features: (1) Model definition: const User = sequelize.define("User", { name: DataTypes.STRING, email: { type: DataTypes.STRING, unique: true } });; (2) CRUD: User.create(), User.findAll(), User.findByPk(), User.update(), User.destroy(); (3) Associations: User.hasMany(Post), Post.belongsTo(User) — enables eager loading with include; (4) Migrations: versioned database schema changes; (5) Hooks: beforeCreate, afterUpdate — for side effects like password hashing; (6) Transactions: atomic operations with sequelize.transaction(async t => { ... });. While Sequelize is powerful, many newer projects prefer Prisma for its better TypeScript support and developer experience.

Common Mistake

A common mistake is memorizing definitions without understanding implications. When asked this question, go one level deeper — explain what happens when this concept is misused or ignored.