Reference
newt add backend
Adds another backend to a monorepo, in a folder of its own.
newt add backend adds a backend to a monorepo made with newt init --monorepo. Each backend is a separate package with its own contexts, port and .env.
newt add backend <folder> [options]Arguments
Section titled “Arguments”| Argument | Meaning |
|---|---|
folder |
Where the backend goes, inside the monorepo, as in apps/admin |
The folder’s last part is the backend’s package name.
Options
Section titled “Options”| Option | Default | Meaning |
|---|---|---|
--port <port> |
next free | The port it serves on, 1 to 65535 |
--db <database> |
sqlite |
sqlite, postgres, mysql or memory |
--files <storage> |
local |
local, s3 or memory |
--cluster <cluster> |
memory |
memory or valkey |
It also takes the global flags.
- Without
--port, it takes the highestPORTfound in the workspaces’.env,.env.localor.env.example, plus 10. With none,3000. - With
--portset to a port another workspace uses, it warns that a request may reach either.
Name rules
Section titled “Name rules”The folder’s last part follows the same rules as a project name: lowercase letters, digits and - . _ ~, a letter or digit at each end, not node_modules.
What it writes
Section titled “What it writes”newt add backend apps/admin skipped package.json (up to date) created apps/admin/package.json created apps/admin/tsconfig.json created apps/admin/eslint.config.ts created apps/admin/AGENTS.md created apps/admin/src/backend.ts created apps/admin/src/stores.ts created apps/admin/src/env.ts created apps/admin/src/backend.test.ts created apps/admin/src/contexts.ts created apps/admin/src/index.ts created apps/admin/src/auth.ts created apps/admin/.env created apps/admin/.env.example created apps/admin/.gitignore created apps/admin/CLAUDE.md
Next steps: bun install cd apps/admin bun run dev- The backend gets the same files as one from
newt init. - The root
package.jsongets the shared devDependencies, and aworkspacespattern for the folder when none covers it.
Next steps
Section titled “Next steps”bun install, at the monorepo’s rootcd <folder>bun run dev
Errors
Section titled “Errors”- Not in a monorepo (no
package.jsonwithworkspaceshere or in a parent folder): usenewt init. - A folder outside the monorepo, or its root: refused.
- A folder inside
node_modules: refused. - A folder that is a package already, and not a newt backend: refused.
- A folder that holds another workspace: refused; put the backend beside it.
- A name another workspace has: refused; two packages of a monorepo never share a name.
- A folder left out by a
!pattern inworkspaces: refused until you take the pattern out.
See Monorepos.