1.medusajs quick start
in Ubuntu / medusa version v1.7.12
nodejs version
1 | ➜ ~ node -v |
Quickstart
Install Medusa CLI
1
npm install -g @medusajs/medusa-cli
Create a new Medusa project
1
medusa new my-medusa-store --seed
Start redis (in ubuntu)
1
2
3
4
5
6
7
8sudo 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
OKStart 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=#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,
};Init data for postgres DB
1
medusa migrations run
Start your Medusa engine
1
medusa develop
Use the API, check medusa server status.
1
curl localhost:9000/store/products
Setting up Admin
Clone this repository
1
2git clone https://github.com/medusajs/admin medusa-admin
cd medusa-adminInstall dependencies
1
yarn install
Start the development server
1
yarn start
Go to http://localhost:7000
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.
Back in your Medusa engine installation directory,
1
npm install medusa-plugin-filestorage-local
Setup config in medusa-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15const 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/",
},
},
];Restart medusa server
1
2
3medusa develop
// or
medusa startthen, 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
- node version
1 | ➜ ~ node -v |
- Install medusa CLI
1 | npm install @medusajs/medusa-cli -g |
- Create a new Medusa project
1 | medusa new my-medusa-store --seed |
- Start your Medusa backend
1 | cd my-medusa-store |
- Test the Backend
1 | curl localhost:9000/store/products |
- PostgreSQL Configurations
1 | const DATABASE_TYPE = process.env.DATABASE_TYPE || "postgres"; |
- Update DB
1 | medusa migrations run |
- medusa can mock Redis for test
For admin dashboard
- back the folder path of medusa, Install the Package of Admin Dashboard
1 | npm install @medusajs/admin |
- Add Admin to Medusa Configurations.
In medusa-config.js
, add the admin plugin into the array of plugins
:
1 | const plugins = [ |
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.
- Start the Admin Dashboard
1 | npm run start |
- Create a New Admin User
1 | medusa user -e some@email.com -p some-password |