---
title: "How to Create An Ecommerce App with Medusa and Ionic"
description: "Learn how to build a powerful ecommerce application with this  step-by-step tutorial using Medusa's server and Ionic SDK. "
url: https://medusajs.com/blog/how-to-create-an-ecommerce-app-with-medusa-and-ionic
last_updated: 2026-08-13T15:21:42Z
---

# How to Create An Ecommerce App with Medusa and Ionic

_Published 2022-08-25 by Silvia O'Dwyer in Ecosystem_

> **Notice** Medusa is under active development, so the content of this post may be outdated. Please check out our documentation instead.
>
> [Go to Docs](http://docs.medusajs.com)

[Ionic](https://ionicframework.com/) is an open source toolkit that allows developers to create cross-platform apps that support a variety of mobile platforms, including Android and iOS. Developers can build with their frontend framework of choice, including Angular, Vue and React.

[Medusa](https://github.com/medusajs/medusa) is an open source composable ecommerce platform that allows developers to create their own customizable and extendable online store. Medusa aims to provide developers with a great experience creating unique ecommerce stores.

In this tutorial, you’ll build an ecommerce app using Medusa and Ionic. This app can then be used on mobile phones such as Android, iOS and Windows phones, and can also be used as a progressive web app (PWA).

You can view the source code for the tutorial in [this repository on GitHub](https://github.com/silvia-odwyer/ionic-medusajs-ecommerce-app).

## Prerequisites

To use Medusa, you need Node.js (version 14+) installed on your machine. You can download it from the official [Node.js website](https://nodejs.org/en/download/).

## Set up the Medusa Server

First, install the Medusa CLI by running the following command in your terminal:

```typescript
npm install -g @medusajs/medusa-cli
```

Next, run the following command to create a new Medusa server:

```typescript
medusa new ecommerce-store-server --seed
```

The `--seed` flag populates the database with demo data that can then be used as part of the ecommerce store later on.

Finally, navigate to the `ecommerce-store-server` directory and start the server:

```typescript
cd ecommerce-store-server
medusa develop
```

If the server runs successfully, you should see in your terminal an output similar to this:

![Medusa_server_console_output](https://assets.medusajs.com/uploads/2024/06/008c734071539bff2f51f018bc848c14ca8957a6-1264x399-9d0mc2uj.webp)

## Install Medusa Admin

Next up, it's time to setup and run the Medusa Admin dashboard. In a separate directory, run the following command:

```typescript
git clone [https://github.com/medusajs/admin](https://github.com/medusajs/admin) medusa-admin
```

Navigate into the newly-created `medusa-admin` directory and install the dependencies for the project:

```typescript
cd medusa-admin
npm install
```

Then, to run the admin, execute the following command in your terminal:

```typescript
npm run develop
```

This runs the Medusa admin on `localhost:7000`. Make sure the Medusa server is also still running.

If you open the Medusa Admin, you should see a login page.

![Login_to_Medusa_Admin](https://assets.medusajs.com/uploads/2024/06/25977986afd632c86a343cd616684c7e8d595ced-1909x909-83y934ut.webp)

Login screen for Medusa Admin

Since you created a Medusa server in the previous section with the `--seed` flag, a test user was created in addition to the demo data. So, you can use the email `admin@medusa-test.com` and password `supersecret` to log in.

The Medusa admin includes many functionalities such as viewing orders, managing products, configuring your store and regions, and much more!

You can try editing some of the existing demo products or adding new products in the Medusa admin.

![Editing_products_in_Medusa_Admin](https://assets.medusajs.com/uploads/2024/06/e405fbb61807072abb7eab15889baacebfc162ca-1892x912-smk44uyb.webp)

Editing a product’s metadata in Medusa Admin

## Initialize An Ionic Project

In this section, you’ll start building the Ionic app.

First, install the Ionic CLI by running the following command:

```typescript
npm install -g @ionic/cli
```

Then, in a separate directory, create a new Ionic app using the following command:

```typescript
ionic start ecommerce-store blank --type=react
```

This tutorial uses React to create the Ionic app. This is specified as part of the command above with the `--type` flag.

It usually takes several minutes to install all the dependencies required for the project.

Once the installation is done, change to the `ecommerce-store` directory and install the other dependencies required:

```typescript
cd ecommerce-store
npm install axios
```

`axios` is used to send asynchronous requests to the Medusa server. This will allow you to perform operations such as fetching products.

### Testing the Ionic App

To test out the blank ionic app, run the following command in your terminal:

```typescript
ionic serve --lab
```

This runs a development Ionic server on `localhost:8100` and the Ionic Lab on `localhost:8200`. You can use the Ionic Lab to simulate how the app looks like on different devices such as iOS or Android.

![Ionic_Lab](https://assets.medusajs.com/uploads/2024/06/8102481bc02fc1169fe41979834ffb2938fb93c2-1913x910-hxnlvtrs.webp)

### Change Store CORS Variable

Since the Ionic app runs on port 8100, you need to update the Store CORS settings on your Medusa server in the `medusa-config.js` file to the following:

```typescript
const STORE_CORS = process.env.STORE_CORS || "http://localhost:8100"
```

For more information, check out this [official guide](https://docs.medusajs.com/troubleshooting/cors-issues/) on updating your CORS settings.

Make sure to restart the Medusa server after making this change.

## Create Product Item Cards

In this section, you’ll create a reusable component to display products as cards on the home page.

First, you need to create two interfaces, one for products and another for images. These interfaces will be used to define the structure of a product and an image.

To do that, create the file `src/Interfaces.tsx` with the following content:

```typescript
export interface Product {
    id: string;
    title: string;
    handle: string;
    images: Image[];
    description: string;
    variants: any[];
}

export interface Image {
    url: string;
}
```

Next, you’ll create the reusable product item card component.

Now that the interfaces are defined and exported, it’s time to create the UI for the product item cards.

Create a new file `src/components/ProductItemCard/ProductItemCard.tsx` with the following content:

```typescript
import React, { useEffect } from 'react';
import { IonCard, IonCardHeader, IonCardSubtitle, IonImg, IonCardTitle } from '@ionic/react';
import { Product } from '../../Interfaces';

const ProductItemCard = ({ product }: { product: Product }) => {

  return (
    <div>
      {product && (
        <IonCard routerLink={"/product/" + product["id"]} className="product_card">
          <IonImg src={product.images[0]["url"]} class="image" />
          <IonCardHeader>
            <IonCardTitle className="product_title"><b>{product["title"]}</b></IonCardTitle>
            <IonCardSubtitle>{product["handle"]}</IonCardSubtitle>
            <IonCardSubtitle>${product["variants"][0]["prices"][1]["amount"] / 100}</IonCardSubtitle>
          </IonCardHeader>
        </IonCard>
      )}
    </div>

  );
};

export default ProductItemCard;
```

Each card displays the image, title, type and price of a product. A product prop will be passed to the component, and its corresponding metadata is then displayed. The `Product` interface is used to enforce the type of the `product` prop.

## Create the Home layout

Now that the component for individual product cards has been created, it’s time to fetch and render the products in the Home layout screen.

The `Home.tsx` and `Home.css` files are created by default in `src/pages` when you initialize an Ionic project. Create a new directory `src/pages/Home` and move `Home.tsx` and `Home.css` into the `src/pages/Home` directory.

### Edit the Header

If you open the `src/pages/Home/Home.tsx` file and take a look at the returned JSX, you'll see a header has automatically been added for you. You can replace the text nested in the component `IonTitle` with the name of your ecommerce store. For example:

```typescript
<IonHeader>
    <IonToolbar>
      <IonTitle>Medusa Ecommerce Store</IonTitle>
    </IonToolbar>
</IonHeader>
```

### Fetch Products from the Medusa Server

Create the file `src/server-url.js` with the following content:

```typescript
const medusaServerBaseURL = "http://localhost:9000";

export default medusaServerBaseURL;
```

It’s useful to define the base URL of the Medusa server in one file. Then, if the port or URL needs to be updated, you only need to update the URL in this file.

If you’re testing on a mobile device, the URL should be changed to your machine’s IP.

Next, in `src/pages/Home/Home.tsx`, replace the imports at the beginning of the file with the following:

```typescript
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar, IonGrid, IonRow, IonCol, } from '@ionic/react';
import './Home.css';
import React, { useEffect, useState } from 'react';
import axios from "axios";
import ProductItemCard from '../../components/ProductItemCard/ProductItemCard';
import medusaServerBaseURL from "../../server-url";
```

Then, create a state variable inside the `Home` component to store the products:

```typescript
const [products, setProducts] = useState([]);
```

And add the following after creating the state variable:

```typescript
useEffect(() => {
    axios
      .get(`${medusaServerBaseURL}/store/products`)
      .then((response) => {

        if (response.data) {
          let products = response.data.products;

          setProducts(products);
        }
      })
      .catch((err) => {
        console.log("error", err)
      });
  }, []);
```

With `useEffect`, the Home component will fetch the products from the server when the screen first opens. A request is sent with `axios` to the [List Products](https://docs.medusajs.com/api/store/#tag/Product/operation/GetProducts) endpoint. Then, the result is used to set the `products` state variable.

### Create A Grid of Products

Next up, it’s time to create a grid of product items using the `<IonGrid>` component.

Still in `src/pages/Home/Home.tsx`, add the following within the `<IonContent>` element in the returned JSX, replacing the `<ExploreContainer>` component:

```typescript
<IonGrid class="ion-no-padding ion-no-margin">
    <IonRow>
     {products.map((product, i) =>
         <IonCol size="6">
             <ProductItemCard product={product} />
         </IonCol>)}
     </IonRow>
</IonGrid>
```

This grid renders each product using the `ProductItemCard` component. Two products are displayed per row, but if you’d like to alter this to a single product per row, update the `size` prop for the `IonCol` element to `12`. For more information on grids in Ionic, be sure to take a look at the [official documentation](https://ionicframework.com/docs/layout/grid).

### Add the CSS

Change the content of `src/pages/Home/Home.css` to add some helpful styling:

```typescript
.product_card {
    cursor: pointer;
}

.product_title {
    font-size: 1em;
}
```

### Testing the Home Screen

Make sure that the Medusa server is still running and re-run the Ionic server if it’s not still running.

If you open the app now in Ionic lab, you should see on the Home screen the products fetched from your Medusa server.

Please note that the screenshot shown is in dark mode due to system preferences. If you use light mode, the screen will look different.

Home screen for the app, listing the products in a grid display

## Create the ProductDetail Screen

In this section, you’ll create the `ProductDetail` screen. This screen will display the individual product’s information and image.

Create the file `src/pages/ProductDetailPage/ProductDetailPage.tsx` with the following content:

```typescript
import { IonContent, IonHeader, IonPage, IonTitle, IonToolbar } from '@ionic/react';
import './ProductDetailPage.css';
import React, { useEffect, useState } from 'react';
import { IonCard, IonCardHeader, IonBackButton, IonButtons, IonCardSubtitle, IonToast, IonImg, IonCardTitle, IonCardContent, IonButton } from '@ionic/react';
import axios from "axios";
import { RouteComponentProps } from 'react-router-dom';
import { Product } from '../../Interfaces';
import medusaServerBaseURL from "../../server-url";

const ProductDetailPage: React.FC<RouteComponentProps<{ id: string }>> = (props) => {
  const [product, setProduct] = useState<Product>();

  useEffect(() => {
    let product_id = props.match.params.id;

    axios
      .get(`${medusaServerBaseURL}/store/products/${product_id}`)
      .then((response) => {
        if (response.data.product) {
          setProduct(response.data.product);
        }
      })
      .catch((err) => {
        console.log("error", err)
      });
  }, [props.match.params.id])

  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonButtons slot="start">
            <IonBackButton text="">
            </IonBackButton>
          </IonButtons>
          <IonTitle>Medusa Ecommerce Store</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent fullscreen>

        {product && (

          <IonCard mode="ios">
            {product["images"] && (
              <IonImg class="product_detail_img" src={product.images[0]["url"]} />
            )}
            <IonCardHeader>
              <div className="metaInfo">
                <IonCardTitle>{product["title"]}</IonCardTitle>
                <IonCardSubtitle>{product["handle"]}</IonCardSubtitle>
                <h3>${product["variants"][0]["prices"][1]["amount"] / 100}</h3>
              </div>

            </IonCardHeader>
            <IonCardContent>
              <h3>Description</h3>
              {product["description"]}
              <IonButton class="button" size="default" shape="round" expand="block">Add to Cart</IonButton>

            </IonCardContent>
          </IonCard>
        )}

      </IonContent>
    </IonPage>
  );
};

export default ProductDetailPage;
```

In this page, the product ID is retrieved from the route parameters. Then, the `axios` library is used to send a request to the [Retrieve Product](https://docs.medusajs.com/api/store/#tag/Product/operation/GetProductsProduct) endpoint on the Medusa server to retrieve the individual product’s data. Then, the `product` state variable is set using the response of the request.

Next, create the file `src/pages/ProductDetailPage/ProductDetailPage.css` with the following content:

```typescript
.product_detail_img {
    height: 30vh;
    object-fit: cover;
}

@media (prefers-color-scheme: light) {  
    h3 {   
         color: black;  
    }
}

h3 {
    font-weight: bold;
}

.button {
    margin-top: 1em;
}

.metaInfo {
    display: flex;
    flex-direction: column;
    flex-wrap: wrap;
}
```

### Add a New Route

To actually use the new screen, it must be added as a new route in the app.

First, import the `ProductDetailPage` component in `src/App.tsx`:

```typescript
import ProductDetailPage from './pages/ProductDetailPage/ProductDetailPage';
```

Then, add the new route into the list of routes defined in `App`:

```typescript
const App: React.FC = () => (
  <IonApp>
    <IonReactRouter>
      <IonRouterOutlet>
        <Route exact path="/home">
          <Home />
        </Route>
        <Route exact path="/">
          <Redirect to="/home" />
        </Route>
        <Route path="/product/:id/" component={ProductDetailPage} />

      </IonRouterOutlet>
    </IonReactRouter>
  </IonApp>
);
```

### Test Product Details Screen

While the Medusa and Ionic development servers are still running, open the Ionic Lab in your browser and click on one of the products in the home screen. A new screen opens showing the product’s details.

### Show Add to Cart Notification

In this section, you’ll add a simple toast notification when the Add to Cart button is clicked. This doesn’t actually add the product to cart but only simulates the functionality.

In the `src/pages/ProductDetailPage/ProductDetailPage.tsx` file, add the following after the creation of the `product` state variable to create a new state variable managing the visibility of the toast notification:

```typescript
const [showToast, setShowToast] = useState(false);
```

Then, add an `IonToast` component in the returned JSX. It should be placed within `IonContent` and after the `IonCard` component:

```typescript
<IonContent fullscreen>
   {product && (

     <IonCard mode="ios">
            ...
     </IonCard>
    )}

    <IonToast
      isOpen={showToast}
      onDidDismiss={() => setShowToast(false)}
      message="Product added to cart"
      duration={800}
    />

</IonContent>
```

Finally, change the Add to Cart button to add an `onClick` event handler:

```typescript
<IonButton class="button" size="default" shape="round" expand="block"  
onClick={() => setShowToast(true)}>Add to Cart</IonButton>
```

Now, whenever the button is clicked, the value of `showToast` is set to `true` to show the toast notification.

### Testing the Notification

While the Medusa and Ionic development servers are still running, on the details screen of one of the products click the Add to Cart button. A toast notification will then be shown for a few seconds indicating that the product was added to cart.

## What’s Next?

By following this tutorial, you’ve successfully connected your Ionic app to your Medusa server, and fetched products from the server.

More features can be added using your Medusa server in your Ionic app including:

- Adding [cart functionalities](https://docs.medusajs.com/guides/carts-in-medusa) that allows the customer to add items to their carts and manage its content.
- Implement the [Checkout flow](https://docs.medusajs.com/advanced/storefront/how-to-implement-checkout-flow/) to allow customers to place an order
- Integrating a payment provider such as [Stripe](https://docs.medusajs.com/add-plugins/stripe/)

> Should you have any issues or questions related to Medusa, then feel free to reach out to the Medusa team via [Discord](https://discord.gg/F87eGuwkTp).
