Reference
newt init
Creates a backend, or a monorepo with a first backend, in a new folder or in the current one.
newt init creates a new project: one backend, or a monorepo (several packages in one repository) with its first backend.
newt init [name] [options]bun create newt [name] [options]Arguments
Section titled “Arguments”| Argument | Meaning |
|---|---|
name |
The project’s folder and package name. . uses the current folder and names the package after it. |
Without a name, in an interactive terminal, newt init asks for it (suggesting my-app) and then asks A backend or a monorepo?. Without a terminal, or with --json, the name is required.
Options
Section titled “Options”| Option | Default | Meaning |
|---|---|---|
--db <database> |
sqlite |
sqlite, postgres, mysql or memory |
--files <storage> |
local |
local, s3 or memory |
--cluster <cluster> |
memory |
memory or valkey: what the backend’s instances share |
--port <port> |
3000 |
The port it serves on, 1 to 65535 |
--monorepo |
off | Makes a monorepo, empty unless --backend is given |
--backend <folder> |
none | The first backend’s folder, as apps/api; with --monorepo only |
It also takes the global flags.
--dband--filesdecide what every context of the backend opens. See Database and migrations and Files.--cluster valkeyis for running several instances. Tests still use the memory cluster.
Name rules
Section titled “Name rules”- Lowercase letters, digits and
- . _ ~, with a letter or digit at each end. At most 214 characters. Notnode_modules. - A name that breaks them is refused with a suggestion:
My Appsuggestsmy-app. --backendmust be a folder inside the monorepo, and its last part follows the same rules.
What it writes
Section titled “What it writes”newt init newthub created newthub/package.json created newthub/tsconfig.json created newthub/eslint.config.ts created newthub/AGENTS.md created newthub/src/backend.ts created newthub/src/stores.ts created newthub/src/env.ts created newthub/src/backend.test.ts created newthub/src/contexts.ts created newthub/src/index.ts created newthub/src/auth.ts created newthub/.env created newthub/.env.example created newthub/.gitignore created newthub/CLAUDE.md
Next steps: cd newthub bun install bun run dev| File | When |
|---|---|
src/env.ts |
When the stores need variables: --db postgres, --db mysql, --files local or --files s3 |
src/test-database.ts |
With --db postgres or --db mysql |
.env, .env.example |
Always: PORT, plus the variables of --files and --cluster |
What each file is for: Project structure. Every variable: Configuration.
With --monorepo, it also writes the root’s package.json, AGENTS.md, .gitignore and CLAUDE.md, and puts the backend in --backend, if given; without it, the monorepo is empty, its workspaces taking apps/.
In a folder that has files
Section titled “In a folder that has files”newt init . or a folder that exists works too:
- Files already there are kept (
skipped).package.jsonand.envonly get what they lack. - A
tsconfig.json,src/index.tsorsrc/auth.tsthat lacks what newt needs is kept, with a warning that says what to add. - The
index.tsthatbun initwrites, if unchanged, is removed, with its"module"key inpackage.json: the backend starts atsrc/index.ts. - If the folder is a backend already, its database, files, cluster and
PORTare kept over the options, with a warning for each that differs. - Another
eslint.config.*in the folder gives a warning.
Next steps
Section titled “Next steps”cd <name>(unless you used.)bun installbun run dev
Errors
Section titled “Errors”- A bad name:
'<name>' cannot name a folder and a package, with a suggestion. - More than one name:
newt init takes one name. --backendwithout--monorepo: refused; add--monorepo.- Inside a monorepo: refused; use
newt add backendinstead. - Inside another backend: refused; make the project in a folder of its own.
--monorepoon a backend folder: refused; a monorepo goes in a folder of its own.- A bad
--db,--files,--clusteror--port: refused, listing the accepted values.