This is a template for building a Shopify app using Node and React. It contains the basics for building a Shopify app.
Rather than cloning this repo, you can use your preferred package manager and the Shopify CLI with these steps.
Shopify apps are built on a variety of Shopify tools to create a great merchant experience. The create an app tutorial in our developer documentation will guide you through creating a Shopify app using this template.
The Node app template comes with the following out-of-the-box functionality:
This template combines a number of third party open-source tools:
The following Shopify tools complement these third-party tools to ease app development:
This template can be installed using your preferred package manager:
Using yarn:
yarn create @shopify/app
Using npx:
npm init @shopify/app@latest
Using pnpm:
pnpm create @shopify/app@latest
This will clone the template and install the required dependencies.
The Shopify CLI connects to an app in your Partners dashboard. It provides environment variables, runs commands in parallel, and updates application URLs for easier development.
You can develop locally using your preferred package manager. Run one of the following commands from the root of your app.
Using yarn:
yarn dev
Using npm:
npm run dev
Using pnpm:
pnpm run dev
Open the URL generated in your console. Once you grant permission to the app, you can start development.
This template uses SQLite to store session data. The database is a file called database.sqlite which is automatically created in the root. This use of SQLite works in production if your app runs as a single instance.
The database that works best for you depends on the data your app needs and how it is queried. You can run your database of choice on a server yourself or host it with a SaaS company. Here’s a short list of databases providers that provide a free tier to get started:
| Database | Type | Hosters |
|---|---|---|
| MySQL | SQL | Digital Ocean, Planet Scale, Amazon Aurora, Google Cloud SQL |
| PostgreSQL | SQL | Digital Ocean, Amazon Aurora, Google Cloud SQL |
| Redis | Key-value | Digital Ocean, Amazon MemoryDB |
| MongoDB | NoSQL / Document | Digital Ocean, MongoDB Atlas |
To use one of these, you need to change your session storage configuration. To help, here’s a list of SessionStorage adapters.
The frontend is a single page app. It requires the SHOPIFY_API_KEY, which you can find on the page for your app in your partners dashboard. Paste your app’s key in the command for the package manager of your choice:
Using yarn:
cd web/frontend/ && SHOPIFY_API_KEY=REPLACE_ME yarn build
Using npm:
cd web/frontend/ && SHOPIFY_API_KEY=REPLACE_ME npm run build
Using pnpm:
cd web/frontend/ && SHOPIFY_API_KEY=REPLACE_ME pnpm run build
You do not need to build the backend.
When you’re ready to set up your app in production, you can follow our deployment documentation to host your app on a cloud provider like Heroku or Fly.io.
When you reach the step for setting up environment variables, you also need to set the variable NODE_ENV=production.
express.json middlewareIf you use the express.json() middleware in your app and if you use Shopify.Webhooks.Registry.process() to process webhooks API calls from Shopify (which we recommend), the webhook processing must occur before calling app.use(express.json()). See the API documentation for more details.
When running the app with the CLI in development mode on Firefox, you might see your app constantly reloading when you access it. That happened in previous versions of the CLI, because of the way HMR websocket requests work.
We fixed this issue with v3.4.0 of the CLI, so after updating it, you can make the following changes to your app’s web/frontend/vite.config.js file:
Change the definition hmrConfig object to be:
const host = process.env.HOST
? process.env.HOST.replace(/https?:\/\//, "")
: "localhost";
let hmrConfig;
if (host === "localhost") {
hmrConfig = {
protocol: "ws",
host: "localhost",
port: 64999,
clientPort: 64999,
};
} else {
hmrConfig = {
protocol: "wss",
host: host,
port: process.env.FRONTEND_PORT,
clientPort: 443,
};
}
Change the server.host setting in the configs to "localhost":
server: {
host: "localhost",
...
When you’re previewing your app or extension, you might see an ngrok interstitial page with a warning:
You are about to visit <id>.ngrok.io: Visit Site
If you click the Visit Site button, but continue to see this page, then you should run dev using an alternate tunnel URL that you run using tunneling software.
We’ve validated that Cloudflare Tunnel works with this template.
To do that, you can install the cloudflared CLI tool, and run:
# Note that you can also use a different port
cloudflared tunnel --url http://localhost:3000
In a different terminal window, navigate to your app’s root and call:
# Using yarn
yarn dev --tunnel-url https://tunnel-url:3000
# or using npm
npm run dev --tunnel-url https://tunnel-url:3000
# or using pnpm
pnpm dev --tunnel-url https://tunnel-url:3000