1.medusajs quick start

in Ubuntu / medusa version v1.7.12

nodejs version

1
2
3
4
➜  ~ node -v
v16.14.1
➜ ~ npm -v
8.5.0

Quickstart

  1. Install Medusa CLI

    1
    npm install -g @medusajs/medusa-cli
  2. Create a new Medusa project

    1
    medusa new my-medusa-store --seed
  3. Start redis (in ubuntu)

    1
    2
    3
    4
    5
    6
    7
    8
    sudo systemctl restart redis-server
    ➜ ~ redis-cli
    127.0.0.1:6379> select
    (error) ERR wrong number of arguments for 'select' command
    127.0.0.1:6379> select 1
    OK
    127.0.0.1:6379[1]> FLUSHDB
    OK
  4. Start postgres DB (in ubuntu)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    ➜  ~ sudo /etc/init.d/postgresql start
    [sudo] password for zhuang:
    ➜ ~
    ➜ ~ sudo -i -u postgres
    postgres@elementoryos61:~$ psql
    psql (12.9 (Ubuntu 12.9-0ubuntu0.20.04.1))
    Type "help" for help.
    postgres=# CREATE DATABASE openharbor_marketplace_medusa;
    CREATE DATABASE
    postgres=#
  5. Config postgress

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    // CORS when consuming Medusa from admin
    const ADMIN_CORS = process.env.ADMIN_CORS || "http://localhost:7000,http://localhost:7001";

    // CORS to avoid issues when consuming Medusa from a client
    const STORE_CORS = process.env.STORE_CORS || "http://localhost:8000";

    // Database URL (here we use a local database called medusa-development)
    const DATABASE_URL =
    process.env.DATABASE_URL || "postgres://postgres:postgres@localhost:5432/openharbor_marketplace_medusa";

    // Medusa uses Redis, so this needs configuration as well
    const REDIS_URL = process.env.REDIS_URL || "redis://localhost:6379";

    // This is the place to include plugins. See API documentation for a thorough guide on plugins.
    const plugins = [
    `medusa-fulfillment-manual`,
    `medusa-payment-manual`,
    ];

    module.exports = {
    projectConfig: {
    redis_url: REDIS_URL,
    // For more production-like environment install PostgresQL
    database_url: DATABASE_URL,
    database_type: "postgres",
    // database_database: "./medusa-db.sql",
    //database_type: "sqlite",
    store_cors: STORE_CORS,
    admin_cors: ADMIN_CORS,
    },
    plugins,
    };
  6. Init data for postgres DB

    1
    medusa migrations run
  7. Start your Medusa engine

    1
    medusa develop
  8. Use the API, check medusa server status.

    1
    curl localhost:9000/store/products

Setting up Admin

  1. Clone this repository

    1
    2
    git clone https://github.com/medusajs/admin medusa-admin
    cd medusa-admin
  2. Install dependencies

    1
    yarn install
  3. Start the development server

    1
    yarn start
  4. Go to http://localhost:7000

  5. Back in your Medusa engine installation directory, you can create your own user for the admin by running:

    1
    medusa user -e some@email.com -p some-password

Setup medusa-plugin-filestorage-local

setup medusa local file service for Images of product which support you create product in Admin.

  1. Back in your Medusa engine installation directory,

    1
    npm install medusa-plugin-filestorage-local
  2. Setup config in medusa-config.js

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    const plugins = [
    `medusa-fulfillment-manual`,
    `medusa-payment-manual`,
    {
    resolve: `medusa-plugin-filestorage-local`,
    options: {
    // The baseurl for your medusajs server
    serverBaseUrl: "http://localhost:9000",
    // when enabled saves the file as a base64 encoded string inside the database (deleting that row is not yet supported)
    saveInDatabase: false, // recommended: false
    // the folder where your files are stored on the server
    fileLocation: "uploads/persistent/",
    },
    },
    ];
  3. Restart medusa server

    1
    2
    3
    medusa develop
    // or
    medusa start
  4. then, you can create a product in medusa admin. e.g. http://localhost:7000/

====================================================================

in Mac / medusa version v1.10.1

Follow the medusa guide https://docs.medusajs.com/development/backend/prepare-environment

  1. node version
1
2
➜  ~ node -v   
v18.16.0
  1. Install medusa CLI
1
2
3
4
npm install @medusajs/medusa-cli -g

➜ ~ medusa -v
Medusa CLI version: 1.3.13
  1. Create a new Medusa project
1
medusa new my-medusa-store --seed
  1. Start your Medusa backend
1
2
cd my-medusa-store
medusa develop
  1. Test the Backend
1
curl localhost:9000/store/products
  1. PostgreSQL Configurations
1
2
const DATABASE_TYPE = process.env.DATABASE_TYPE || "postgres";
const DATABASE_URL = process.env.DATABASE_URL || "postgres://postgres:zaq12wsx@localhost:5432/pg-medusa-1-10-1-test";
  1. Update DB
1
medusa migrations run
  1. medusa can mock Redis for test

For admin dashboard

  1. back the folder path of medusa, Install the Package of Admin Dashboard
1
npm install @medusajs/admin
  1. Add Admin to Medusa Configurations.

In medusa-config.js, add the admin plugin into the array of plugins:

1
2
3
4
5
6
7
8
9
10
11
12
const plugins = [
`medusa-fulfillment-manual`,
`medusa-payment-manual`,
// To enable the admin plugin, uncomment the following lines and run `yarn add @medusajs/admin`
{
resolve: "@medusajs/admin",
/** @type {import('@medusajs/admin').PluginOptions} */
options: {
autoRebuild: true,
},
},
];

The plugin accepts the following options:

a. serve: (default: true) a boolean indicating whether to serve the admin dashboard when the Medusa backend starts. If set to false, you can serve the admin dashboard using the dev command.

b. path: (default: app) a string indicating the path the admin server should run on. It shouldn’t be prefixed or suffixed with a slash /, and it can’t be one of the reserved paths: “admin” and “store”.

c. outDir: Optional path for where to output the admin build files.

e. autoRebuild: (default: false) a boolean indicating whether the admin UI should be rebuilt if there are any changes or if a missing build is detected when the backend starts. If not set, you must manually build the admin dashboard.

  1. Start the Admin Dashboard
1
npm run start
  1. Create a New Admin User
1
medusa user -e some@email.com -p some-password