Install Medusa Backend
This document will guide you through setting up your Medusa backend in a three steps.
Prerequisites
Before you can install and use Medusa, you need the following tools installed on your machine:
Create a Medusa Backend
It is recommended to use Yarn for the installation process as it's much faster than using NPM.
1. Install Medusa CLI
If you run into any errors while installing the CLI tool, check out the troubleshooting guide.
2. Create a new Medusa project
medusa new my-medusa-store
You'll then be asked to specify your PostgreSQL database credentials. You can choose "Continue" to use the default credentials shown in the terminal, choose "Change credentials" to specify your PostgreSQL credentails, or choose "Skip database setup" to create the database later.
If you choose "Skip database setup" you will need to set the database configurations and run migrations later.
3. Start your Medusa backend
Make sure your PostgreSQL server is running before you run the Medusa backend.
cd my-medusa-store
medusa develop
After these three steps and in only a couple of minutes, you now have a complete commerce engine running locally. You can test it out by sending a request using a tool like Postman or through the command line:
curl localhost:9000/store/products
Troubleshooting Installation
Error: SASL: SCRAM-SERVER-FIRST-MESSAGE: Client password must be a string
You may get the following error while running medusa new
or while running integration tests during local development:
If the error occurs while running medusa new
and you've selected to enter your database credentials, either:
- Make sure your database credentials are correct;
- Or choose the Skip option to skip entering your database credentials.
If the error occurs while running integration tests, make sure the following variable is set in your system's environment variable:
Error: connect ECONNREFUSED ::1:5432
When you start your Medusa backend you may run into the following error:
This error occurs because the backend couldn't connect to the PostgreSQL database. The issue could be one of the following:
- PostgreSQL server isn't running. Make sure it's always running while the Medusa backend is running.
- The connection URL to your PostgreSQL database is incorrect. This could be because of incorrect credentials, port number, or connection URL format. The format should be
postgres://[user][:password]@[host][:port]/[dbname]
. Make sure that the connection URL format is correct, and the credentials passed in the URL are correct. You can learn more about formatting the connection URL here
AwilixResolutionError: Could Not Resolve X
If you get the error on a fresh installation of the Medusa backend, or you haven't made any customizations that would cause this error, try to remove the node_modules
directory, then run the following command in the root directory of the Medusa backend to re-install the dependencies:
Seed Data
For better testing, you can add demo data to your Medusa backend by running the seed command in your Medusa backend directory:
Health Route
You can access /health
to get health status of your backend.
Next Steps
Learn about the different resources that your Medusa backend is made of.
Learn about configuring your backend and loading environment variables.