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.

Integrating the model into our application

Integrating the model into our application - Node.js Tutorial

From the course: Databases for Node.js Developers

Integrating the model into our application

- [Narrator] As I said, we need to make this model we just created now accessible in our Fastify application. To do that, we will update our Mongoose plugin. So I open that. It's in source, plugins, databases, mongoose. The goal is to attach the item model to the Fastify instance so that it's available throughout our app. The best way to do this in Fastify is by using decorators. Decorators allow us to add properties or methods to the Fastify instance, making them accessible everywhere in the application on the Fastify object that is as you also see on line four, always passed around through all our plugins that we're using, and routes are also basically plugins. In other frameworks, you might simply import the model wherever it's needed. This works in Fastify, too, but it's not a deal for a modular setup. Using decorators ensures a consistent way to use your models throughout your application. So what I'm doing now right on top is I will import the item model. So I add import. In…

Contents