TypeScript Getting Started
This page takes you from an empty directory to a running Putnami app with Bun alone: no Putnami CLI, no workspace. It then shows the Putnami CLI as the next step, for a workspace of several projects.
Follow it top to bottom: every command runs from a shell, and each step says what you should see.
Prerequisites
Bun 1.4 or later, on macOS or Linux:
bun --versionWhen the command is missing or prints an older release, install Bun with
curl -fsSL https://bun.sh/install | bash, open a new shell, and check again.
The first install also needs network access to the npm registry.
Create the app
For a React application, server-rendered, with file-based pages:
bun create @putnami my-app
cd my-app
bun install
bun devFor an HTTP API service, with JSON endpoints and no React:
bun create @putnami my-api --template server
cd my-api
bun install
bun devbun create @putnami runs the package @putnami/create. It writes the project
into a new or empty directory and prints the next commands:
Created my-app from typescript-web in my-app
Next:
cd my-app
bun install
bun devbun install installs the @putnami/* packages at the release that
@putnami/create shipped with, and writes bun.lock.
Run it
bun dev generates the routes, serves the app on port 3000, and keeps running.
Once the server accepts connections, it prints this line, with its own
duration:
putnami-dev: generated in 1240ms, serving on port 3000The server's own log, printed before it, names the same address:
⚡️ listening http://localhost:3000.
Open http://localhost:3000:
- the web app answers with its home page, which links to
/aboutand/guestbook; - the API service answers
{"message":"Hello, World!"}, andcurl 'http://localhost:3000/?name=Putnami'answers{"message":"Hello, Putnami!"}.
Edit a file under src/ and save it: bun dev generates again and reloads the
server, and a new route file answers without a restart. Stop it with Ctrl-C.
Port 3000 taken? bun dev says so; serve on another port with
PORT=3001 bun dev.
Where the code goes
| Path | Holds |
|---|---|
src/main.ts |
The application: the plugins it uses |
src/serve.ts |
The entry bun dev serves |
src/app/ |
Web app: one folder per route, with page.tsx, loader.ts, action.ts, and layout.tsx around them |
src/api/ |
API service: one file per method and route, such as get.ts for GET / |
test/ |
The tests bun test runs |
AGENTS.md |
What a coding agent needs: the commands, and where each package's reference lives |
Each @putnami/* package ships a quick reference at
node_modules/@putnami/<package>/AI.md.
Test it
bun testThe tests start the app in process with createTestApp and call it over HTTP;
a web app's first run generates its pages, so it takes a few seconds more. A
test that needs PostgreSQL reads the database from DATABASE_URL:
DATABASE_URL=postgres://postgres:postgres@localhost:5432/app bun testSee Testing for the test app, and Persistence for the database.
Bun runs TypeScript without checking its types, so bun test passes a test
over code the project's tsconfig.json refuses, such as process.env.PORT
where the strict config asks for process.env['PORT']. Check the types on
their own with:
bun run typecheckIt runs tsc --noEmit with the typescript the project installs, and prints
the compiler's diagnostics.
Build it
bun run buildbun run build generates the routes, bundles the app, type-checks the project,
and compiles it into one production executable, dist/serve.bundled-<os>-<arch>
(for instance dist/serve.bundled-linux-x64). A type error prints the
compiler's diagnostics and stops the build before it compiles anything, as
putnami build does; bun run typecheck checks the same sources and the
tests, without building. Run the executable from the project directory:
PORT=8080 ./dist/serve.bundled-linux-x64A web app's executable serves its client files, the scripts and stylesheets
the browser loads, from .gen/public under the directory it runs from: started
from anywhere else, its pages render but their scripts and styles answer with
an error. To run the app on another machine, build its container image instead:
--image compiles for Linux and stages the client files and a Dockerfile
beside the executable.
bun run build -- --image
docker build distbun dev, bun test and bun run build run the generate step themselves. To
run it alone, to read the generated code under .gen/:
bun run putnami-generateStyle it
A page, a layout or a component of a web app styles itself by importing CSS: a
plain stylesheet such as the template's src/app/styles.css, a CSS Module
(*.module.css), or Tailwind. The build compiles them into hashed static
files, and bun dev rebuilds them when a .css file changes. See
Styling; the full guide ships with
the package, at node_modules/@putnami/web/doc/styling.md.
Try the canary
npmjs receives @putnami/create at each release. Every build of main
publishes it to the canary dist-tag of https://npm.putnami.dev, which serves
the @putnami scope only: to try the canary, map the scope in
~/.bunfig.toml, then pass the registry to the project.
[install.scopes]
"@putnami" = "https://npm.putnami.dev"bunx @putnami/create@canary my-app --registry https://npm.putnami.devNext: the Putnami CLI
The app above runs with Bun alone. The Putnami CLI runs the same steps across a
workspace of projects, TypeScript, Go and Python, and adds lint, the impacted
gate, publishing and container images. Install it on macOS or Linux; the
second line makes putnami reachable in the shell you are in:
curl -fsSL https://putnami.dev/install.sh | bash
export PATH="$HOME/.putnami/bin:$PATH"Getting Started says what the installer checks and does. Then, from an empty directory:
putnami initYou do not install Bun for the CLI: putnami init uses a Bun the machine
already holds when it fits, and installs one under the Putnami home otherwise.
The workspace records the release in package.json#packageManager and
putnami.lock.json, and every task runs with that exact release.
| You need... | Template | What you get |
|---|---|---|
| A React SSR application | typescript-web |
File-based pages, layouts, loaders, actions, islands, static assets |
| An HTTP API service | typescript-server |
API routing, handlers, tests, application runtime |
| A shared TypeScript package | typescript-library |
Package exports, tests, workspace dependency wiring |
putnami projects create web --template typescript-web
putnami deps install
putnami serve webputnami init <name> also creates a first project from the typescript-web
template, and --template server from typescript-server; putnami init --help
lists every template. The
daily loop:
putnami serve web
putnami test web
putnami lint,test,build --impacted--impacted keeps the feedback loop scoped to the projects affected by your
branch.
With Bun alone
Without the Putnami CLI or a workspace, bun create starts the same web or
API project from the same templates:
bun create @putnami web # a React SSR application
bun create @putnami api --template server # an HTTP API service
cd web
bun install
bun devbun create @putnami runs the package @putnami/create. The project it creates
pins each @putnami/* package to the release that package shipped with, and
runs bun dev, bun test and bun run build with Bun alone. Its AGENTS.md
points an agent at each package's node_modules/@putnami/<package>/AI.md.
npmjs receives @putnami/create at each release. Every build of main
publishes it to the canary dist-tag of https://npm.putnami.dev, which serves
the @putnami scope only: to try the canary, map the scope in
~/.bunfig.toml, then pass the registry to the project.
[install.scopes]
"@putnami" = "https://npm.putnami.dev"bunx @putnami/create@canary web --registry https://npm.putnami.devWhat to look at first
Start with the project shape, then add framework depth only when the app needs it:
- Web for React SSR, routing, loaders, actions, and islands.
- API for HTTP endpoints and server-side handlers.
- Configuration when the first environment variable appears.
- Dependency injection before runtime wiring becomes implicit.
- Testing before the project becomes a dependency for another project.
- Persistence when the service needs Postgres: the connection, migrations, and tests against the database.
- Publish & Docker to build the binary or the container image.
Read next
- TypeScript overview for the package map and runtime model.
- Extension for build, test, lint, serve, publish, and Docker behavior.
- CLI for the shared graph and CLI model.