Files
medusa-store/www/apps/docs/content/development/loaders/overview.mdx
2023-09-25 19:03:00 +03:00

42 lines
1.6 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
description: "Learn what loaders are in Medusa. A loader is a script that runs when the Medusa backend starts."
---
import DocCard from '@theme/DocCard';
import Icons from '@theme/Icon';
# Loaders
In this document, youll learn what loaders are in Medusa.
## Overview
A loader is a script that runs when the Medusa backend starts. The Medusa backend uses loaders to initialize the database connection, load plugins, register resources in the dependency container, and more.
Loaders can be created within the Medusa backend codebase, in a plugin, or in a module to perform custom actions when the backend starts. The loader is created in a TypeScript or JavaScript file located in the `src/loaders` directory, then transpiled using the `build` command into the `dist/loaders` directory.
### Loader Examples
For example, the Redis Event Bus module uses a loader to establish a connection with Redis and log a message in the console.
Another example is the Algolia plugin, which uses a loader to update the index settings when the Medusa backend starts based on the plugins options.
Loaders can be used to access the dependency container and register custom resources in it.
Loaders can also be used to create [scheduled jobs](../scheduled-jobs/overview.mdx) that run at a specified interval of time.
---
## Custom Development
Developers can create a loader with the desired functionality directly within the Medusa Core, in a plugin, or in a module.
<DocCard item={{
type: 'link',
href: '/development/loaders/create',
label: 'Create a Loader',
customProps: {
icon: Icons['academic-cap-solid'],
description: 'Learn how to create a loader.'
}
}} />