# snizu app create

Source: https://snizu.dev/docs/cli/app/create

## Usage [#usage]

```sh title="Usage"
snizu app create <dir> [--template node]
```

## Arguments and flags [#arguments-and-flags]

<Fields>
<Field name="<dir>" type="path" required>
Where to write the app. A folder with a `package.json` already in it is refused. Its name becomes the package's name.
</Field>

<Field name="--template" type="node">
The app to start from. `node` is the only one, and the default.
</Field>
</Fields>

It needs no sign-in: the app is written from files inside the CLI.

## What it writes [#what-it-writes]

<Fields>
<Field name="server.js">
Every route, on Node's own `http` module: the install, webhooks, the app proxy and the backends of an embedded page and a checkout block.
</Field>

<Field name="lib/verify.js">
Everything you have to check, written out so you can read it: webhook signatures, app proxy signatures, admin session tokens and checkout block tokens.
</Field>

<Field name="test/verify.test.js">
Tests for each check, run with `npm test` on Node's own test runner.
</Field>

<Field name=".env.example">
The variables the server reads: `CLIENT_ID`, `CLIENT_SECRET`, `APP_URL`, `ADMIN_URL`, `API_URL`, `PORT`.
</Field>

<Field name="package.json">
`npm run dev` (Node's `--watch` with `.env`) and `npm test`. No dependencies.
</Field>

<Field name="README.md, .gitignore">
What's where, and `.env` kept out of git.
</Field>
</Fields>

## The routes [#the-routes]

<Fields>
<Field name="GET /auth/start">
Sends a merchant to install the app. The `state` it sends is tied to their browser with a cookie.
</Field>

<Field name="GET /auth/callback">
Checks the `state`, then swaps the code for a token at `/admin/v1/oauth/token`. The store is the one the token endpoint names, never the one in the address.
</Field>

<Field name="POST /webhooks">
Checks the `shop-signature` on the raw body before reading it. See [Verify webhook signatures](/docs/connections/webhooks/verify-signatures).
</Field>

<Field name="/proxy/*">
Answers `/apps/<your handle>/*` on stores' addresses, once the signature on the query checks out. Add its address as `app_proxy` in your manifest.
</Field>

<Field name="GET /api/me">
Your embedded page's backend: checks the admin session token from [`@snizu/app-bridge`](/docs/apps/embedded-pages).
</Field>

<Field name="GET /api/checkout-block">
Your checkout block's backend: checks its token from [`@snizu/app-bridge/checkout`](/docs/apps/checkout-blocks).
</Field>
</Fields>

## Examples [#examples]

```shellsession title="Terminal"
$ snizu app create gift-wrap
✓ Wrote an app in /home/salma/gift-wrap.
Next: cd gift-wrap, then snizu app init to link it, then npm test and npm run dev.
$ cd gift-wrap
$ cp .env.example .env
$ npm test
```

Then link the folder to an app with [`snizu app init`](/docs/cli/app/init), and put the client ID and secret from the developer console in `.env`.

<Callout title="Tokens live in memory">
The template keeps installs and install states in a `Map`, so a restart forgets them. Move both to your database, with tokens encrypted, before a merchant relies on it.
</Callout>