> ## Documentation Index
> Fetch the complete documentation index at: https://sdk.docs.xano.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Add a backend to an existing app

> Run npx @xano/sdk init inside an app you already have to add a Xano backend in xano/, merge the xano scripts into package.json, and point your frontend at the backend URL.

If you already have a frontend (a Vite app, Next.js, anything with a `package.json`), `init`
adds a Xano backend beside it and leaves your app alone.

<Note>
  **On Windows or an Intel Mac?** There is no Xano Engine build for your machine yet. Wherever this
  page says `npm run xano:deploy`, run `npm run xano:deploy:ephemeral` instead: it deploys the same
  code to an ephemeral in Xano's cloud. That needs a Xano account, so sign in first
  ([Connect to Xano](/start/connect-to-xano)). See
  [where the Engine differs today](/run/xano-engine#where-the-engine-differs-today).
</Note>

## Add the backend

From your app's root:

```bash theme={null}
npx @xano/sdk init
```

In a directory that already has files, `init` asks nothing and writes no frontend. It adds:

* `xano/`, the same empty starter a new project gets. If your `package.json` is not
  `"type": "module"`, it also writes `xano/package.json` with only `{"type": "module"}`, so
  `xano/` loads as ES modules without changing your project.
* The `xano:*` scripts and the backend's dependencies, merged into your `package.json`. Your
  entries win: a dependency you already have keeps its range, and a script you already have
  keeps its command.
* A marked block in `.gitignore` and in `AGENTS.md`. The rest of each file is left as it was.

It writes no README, CI workflow or root `tsconfig.json`. If `init` would overwrite anything
(an existing `xano/`, or a `xano:*` script with a different command), it lists every clash and
writes nothing. `--force` lists what it would overwrite and asks first.

## The scripts it adds

| Script | Target |
| - | - |
| `npm run xano:deploy` | Deploys the backend to the Xano Engine on your machine, keeping its rows (`--keep-data`) |
| `npm run xano:deploy:ephemeral` | Deploys the backend to an ephemeral in Xano's cloud (needs an account) |
| `npm run xano:test` | Runs the tests on the backend you last deployed to |
| `npm run xano:check` | Checks routes, types and `xano.lock` without writing anything; run it from your CI |
| `npm run xano:typecheck` | Type-checks `xano/` under its own `tsconfig.json` |

There is no `xano:deploy:frontend` and no `--static`: your app keeps its own build and hosting.

## Run the backend

```bash theme={null}
npm run xano:deploy
```

It deploys to the Xano Engine and prints the backend URL, for example
`http://127.0.0.1:53358`. `npx xanosdk status` prints it again later.

## Point your frontend at it

In a project `init` scaffolded, the deploy writes the URL into `.env.local` for you. In an
existing app it does not, so set it yourself. For a Vite app, in `.env.local`:

```bash theme={null}
VITE_XANO_HOST=http://127.0.0.1:53358
```

Then read it where you call the backend. If you later serve a build from Xano with
`xanosdk deploy --static`, the deploy injects the backend URL as `window.XANO_HOST`, so read
that first and fall back to the build-time value:

```ts theme={null}
const XANO_HOST =
  (typeof window !== "undefined" && window.XANO_HOST) || import.meta.env.VITE_XANO_HOST;
```

Other frameworks use their own public variable prefix (for example `NEXT_PUBLIC_` in Next.js).
[Typed frontend](/build/typed-frontend) shows how to take request paths and types from
`xano/routes.gen.ts` instead of typing URLs by hand.

<Note>
  If your root `tsconfig.json` includes every `.ts` file (Next.js's does), add `"xano/lambdas"` to
  its `exclude` before you write your first lambda. Lambda code type-checks only under
  `xano/lambdas/tsconfig.json`.
</Note>

## Next

* [Your first change](/build/first-change): add a table and an endpoint.
* [What you built](/start/what-you-built): what to commit, including `xano/xano.lock` and the
  Xano Engine pin in `package.json`.
* [Connect to Xano](/start/connect-to-xano): deploy to Xano's cloud.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.