From the course: Databases for Node.js Developers

Unlock this course with a free trial

Join today to access over 24,400 courses taught by industry experts.

Loading and syncing the models

Loading and syncing the models - Node.js Tutorial

From the course: Databases for Node.js Developers

Loading and syncing the models

- [Instructor] So far, we actually have only created arbitrary functions that don't connect to the database yet. The infrastructure we will create now can be used in any framework to dynamically load and associate Sequelize models. In Fastify, to keep it modular, we will use a Fastify plugin for this again. This will ensure that models are initialized and the relationships are defined when the app starts. So let's get started. For that, I go back into my src, plugins and there databases and sequelize. Let's close the sidebar. We don't need it at this point. And up there, I will have to bring in a few more helpers now. I first import readdir from the Node internal "fs/promises." And I also bring in path, also a Node Core module for path operations on directories from "path". Then I scroll down and right after, we do all the operations for basically connecting to Sequelize. I will now add something new. Let's write deal with models. And there we'll first define an empty object for…

Contents