Skip to main content

Services

In this document, you'll learn about what Services are in Medusa.

What are Services

Services in Medusa represent bundled helper methods that you want to use across your server. By convention, they represent a certain entity or functionality in your server.

For example, you can use Medusa’s productServiceCopy to Clipboard to get the list of products, as well as perform other functionalities related to products. There’s also an authServiceCopy to Clipboard that provides functionalities like authenticating customers and users.

Custom services are TypeScript or JavaScript files located in the src/servicesCopy to Clipboard directory of your Medusa Server installation. Each service should be a class that extends the TransactionBaseServiceCopy to Clipboard class from the core Medusa package @medusajs/medusaCopy to Clipboard.

Each file you create in src/servicesCopy to Clipboard should hold one service and export it.

The file name is important as it determines the name of the service when you need to use it elsewhere. The name of the service will be registered as the camel-case version of the file name + ServiceCopy to Clipboard at the end of the name.

For example, if the file name is hello.tsCopy to Clipboard, the service will be registered as helloServiceCopy to Clipboard. If the file name is hello-world.tsCopy to Clipboard, the service name will be registered as helloWorldServiceCopy to Clipboard.

The registration name of the service is important, as you’ll be referring to it when you want to get access to the service using dependency injection or in routes.


See Also