pickstack

Svelte + Express

Express 5 API as its own server/ project; /api is proxied from the app. This page shows exactly what pickstack adds to a Svelte project for Express: the packages, the new files and the changes to existing ones. Every combination is installed, built, linted and tested in CI.

$ npm create pickstack@latest my-app -- --framework svelte --modules express --yes
Customize in the configurator

New files

server/.env.example
PORT=3001
server/.gitignore
node_modules
dist
.env
server/package.json
{
  "name": "my-app-server",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "dev": "tsx watch --env-file-if-exists=.env src/index.ts",
    "build": "tsc",
    "start": "node --env-file-if-exists=.env dist/index.js",
    "typecheck": "tsc --noEmit"
  },
  "dependencies": {
    "express": "^5.3.0"
  },
  "devDependencies": {
    "@types/express": "^5.0.6",
    "@types/node": "^24.19.2",
    "tsx": "^4.23.15",
    "typescript": "~6.0.3"
  },
  "engines": {
    "node": ">=22.12.0"
  }
}
server/README.md
# my-app-server

Express 5 API on port 3001. Copy `.env.example` to `.env` to change settings.

```bash
npm install
npm run dev
```
server/src/app.ts
import express from "express";

export const app = express();

app.use(express.json());

app.get("/api/health", (_req, res) => {
  res.json({ ok: true });
});

app.get("/api/hello", (req, res) => {
  const name = typeof req.query.name === "string" ? req.query.name : "world";
  res.json({ message: `Hello, ${name}!` });
});
server/src/index.ts
import process from "node:process";
import { app } from "./app.js";

const port = Number(process.env.PORT ?? 3001);

app.listen(port, () => {
  console.log(`API listening on http://localhost:${port}`);
});
server/tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "NodeNext",
    "moduleResolution": "NodeNext",
    "rootDir": "src",
    "outDir": "dist",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "verbatimModuleSyntax": true,
    "types": ["node"]
  },
  "include": ["src"]
}
web/.gitignore
node_modules
dist
.env
.env.local
.DS_Store
web/index.html
<!doctype html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>my-app</title>
  </head>
  <body>
    <div id="app"></div>
    <script type="module" src="/src/main.ts"></script>
  </body>
</html>
web/package.json
{
  "name": "my-app",
  "private": true,
  "version": "0.1.0",
  "type": "module",
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview",
    "typecheck": "svelte-check --tsconfig ./tsconfig.app.json && tsc -p tsconfig.node.json"
  },
  "devDependencies": {
    "@sveltejs/vite-plugin-svelte": "^7.3.2",
    "@tsconfig/svelte": "^5.0.9",
    "@types/node": "^24.19.2",
    "svelte": "^5.59.1",
    "svelte-check": "^4.7.8",
    "typescript": "~6.0.3",
    "vite": "^8.3.8"
  }
}
web/README.md
# my-app

Stack: Svelte 5, Vite, TypeScript, Express.

## Getting started

```bash
npm install
npm run dev
```

## Scripts

- `npm run build`
- `npm run preview`
- `npm run typecheck`

## API

The API lives in `../server` (Express). Start it with `npm run dev` there; requests to `/api` from this app are proxied to it in development.

## Push to GitHub

Create an empty repository on GitHub, then:

```bash
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin https://github.com/<your-username>/my-app.git
git push -u origin main
```
web/src/app.css
:root {
  font-family: system-ui, sans-serif;
  color: #0f172a;
  background: #f8fafc;
}

body {
  margin: 0;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2rem;
  padding: 2rem;
  box-sizing: border-box;
}

.title {
  font-size: 1.875rem;
  margin: 0;
}

.nav {
  display: flex;
  gap: 1rem;
}

.link {
  color: #475569;
  text-decoration: none;
  font-weight: 500;
}

.link:hover {
  color: #0f172a;
}

.page {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
}

.text {
  max-width: 28rem;
  text-align: center;
  color: #475569;
}

.card {
  background: #fff;
  padding: 2rem;
  border-radius: 1rem;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
  text-align: center;
}

.count {
  font-size: 3rem;
  font-weight: 700;
  margin: 0;
  font-variant-numeric: tabular-nums;
}

.row {
  margin-top: 1.5rem;
  display: flex;
  justify-content: center;
  gap: 0.75rem;
}

.btn {
  background: #0f172a;
  color: #fff;
  border: 0;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font: inherit;
  cursor: pointer;
}

.btn:hover {
  background: #334155;
}
web/src/App.svelte
<script lang="ts">
  import ApiGreeting from "./lib/ApiGreeting.svelte";
  import Counter from "./lib/Counter.svelte";
</script>

<main class="app">
  <h1 class="title">my-app</h1>
  <Counter />
  <ApiGreeting />
</main>
web/src/lib/ApiGreeting.svelte
<script lang="ts">
  import { onMount } from "svelte";

  let message = $state("Calling the API…");

  onMount(() => {
    fetch("/api/hello?name=my-app")
      .then((response) => {
        if (!response.ok) throw new Error(`HTTP ${response.status}`);
        return response.json();
      })
      .then((data) => (message = data.message))
      .catch(() => (message = "The API isn't running: start it in server/."));
  });
</script>

<p class="text">{message}</p>
web/src/lib/Counter.svelte
<script lang="ts">
  let count = $state(0);
</script>

<div class="card">
  <p class="count">{count}</p>
  <div class="row">
    <button type="button" class="btn" onclick={() => count--}>-1</button>
    <button type="button" class="btn" onclick={() => count++}>+1</button>
  </div>
</div>
web/src/main.ts
import { mount } from "svelte";
import App from "./App.svelte";
import "./app.css";

const app = mount(App, {
  target: document.getElementById("app")!,
});

export default app;
web/svelte.config.js
/** @type {import("@sveltejs/vite-plugin-svelte").SvelteConfig} */
export default {};
web/tsconfig.app.json
{
  "extends": "@tsconfig/svelte/tsconfig.json",
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
    "target": "es2023",
    "module": "esnext",
    "types": ["svelte", "vite/client"],
    "allowArbitraryExtensions": true,
    "noEmit": true,
    "allowJs": true,
    "checkJs": true,
    "moduleDetection": "force"
  },
  "include": ["src/**/*.ts", "src/**/*.js", "src/**/*.svelte"]
}
web/tsconfig.json
{
  "files": [],
  "references": [
    {
      "path": "./tsconfig.app.json"
    },
    {
      "path": "./tsconfig.node.json"
    }
  ]
}
web/tsconfig.node.json
{
  "compilerOptions": {
    "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
    "target": "es2023",
    "lib": ["ES2023"],
    "types": ["node"],
    "skipLibCheck": true,
    "module": "nodenext",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "moduleDetection": "force",
    "noEmit": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "erasableSyntaxOnly": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["vite.config.ts"]
}
web/vite.config.ts
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [svelte()],
  server: { proxy: { "/api": "http://localhost:3001" } },
});

Project files

Related templates