Installation
This guide covers installing and configuring the Medusa JavaScript SDK in your application.Prerequisites
- Node.js 20 or higher
- A Medusa backend instance running (local or hosted)
- Package manager: npm, yarn, or pnpm
Install the SDK
Install the@medusajs/js-sdk package using your preferred package manager:
Basic Initialization
Storefront Usage
For customer-facing applications, initialize the SDK with your backend URL and publishable API key:Admin Usage
For administrative applications, use an API key for authentication:Never expose admin API keys in client-side code. Use environment variables and keep them server-side only.
Configuration Options
The SDK accepts aConfig object with the following options:
Required Options
string
required
The base URL of your Medusa backend API. In browser environments, you can use
/ or an empty string to use the current origin.Authentication Options
string
The publishable API key for storefront requests. Required for store API access.
string
The secret API key for admin requests. Use only in server-side environments.
object
Advanced authentication configuration.
Request Options
ClientHeaders
Headers to include in all requests.
Debugging Options
boolean
default:"false"
Enable debug logging to console.
Logger
Custom logger implementation.
Common Setup Examples
React Application
Create a dedicated SDK instance file:src/lib/medusa.ts
src/components/ProductList.tsx
Next.js Application
Client Components
src/lib/sdk/client.ts
Server Components
src/lib/sdk/server.ts
app/products/page.tsx
React Native Application
Use AsyncStorage for token persistence:src/lib/medusa.ts
Node.js/Express Backend
Use API key authentication:src/lib/medusa.ts
Vanilla JavaScript
Use via CDN or bundler:Environment Variables
Store your configuration in environment variables:.env.local
Verify Installation
Test your SDK setup:Next Steps
SDK Methods
Learn about available methods and how to use the client
API Authentication
Implement user authentication and session management