Full-stack: React + Express starter
React, an Express 5 API and MongoDB with Mongoose; web/ and server/ side by side. A tested combination you can create in one command and keep extending.
$ npm create pickstack@latest my-app -- --framework react --modules express,mongodb,tailwind,tanstack-query,vitest,testing-library,eslint,prettier --yesCustomize in the configurator
New files
# Local MongoDB for development: docker compose up -d
services:
mongo:
image: mongo:8
ports:
- "27017:27017"
volumes:
- mongo-data:/data/db
volumes:
mongo-data:
PORT=3001 MONGODB_URI=mongodb://localhost:27017/my-app
node_modules dist .env
{
"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",
"mongoose": "^9.13.1"
},
"devDependencies": {
"@types/express": "^5.0.6",
"@types/node": "^24.19.2",
"tsx": "^4.23.15",
"typescript": "~6.0.3"
},
"engines": {
"node": ">=22.12.0"
}
}
# my-app-server
Express 5 API on port 3001, with MongoDB (Mongoose). Copy `.env.example` to `.env` to change settings.
```bash
npm install
npm run dev
```
import express from "express";
import { Todo } from "./models/todo.js";
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}!` });
});
app.get("/api/todos", async (_req, res) => {
const todos = await Todo.find().sort({ createdAt: -1 }).limit(100);
res.json(todos);
});
app.post("/api/todos", async (req, res) => {
const title =
typeof req.body?.title === "string" ? req.body.title.trim() : "";
if (!title) {
res.status(400).json({ error: "title is required" });
return;
}
const todo = await Todo.create({ title });
res.status(201).json(todo);
});
import mongoose from "mongoose";
/** Opens the connection Mongoose models use; call it once, before serving requests. */
export async function connectDb(uri: string) {
await mongoose.connect(uri);
console.log(`Connected to ${mongoose.connection.name}`);
}
import process from "node:process";
import { app } from "./app.js";
import { connectDb } from "./db.js";
const port = Number(process.env.PORT ?? 3001);
await connectDb(process.env.MONGODB_URI ?? "mongodb://localhost:27017/my-app");
app.listen(port, () => {
console.log(`API listening on http://localhost:${port}`);
});
import { model, Schema } from "mongoose";
const todoSchema = new Schema(
{
title: { type: String, required: true, trim: true, maxlength: 200 },
done: { type: Boolean, default: false },
},
{ timestamps: true },
);
export const Todo = model("Todo", todoSchema);
{
"compilerOptions": {
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"rootDir": "src",
"outDir": "dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"verbatimModuleSyntax": true,
"types": ["node"]
},
"include": ["src"]
}
node_modules dist .env .env.local .DS_Store
dist pnpm-lock.yaml package-lock.json yarn.lock bun.lock
{}
import js from "@eslint/js";
import { defineConfig, globalIgnores } from "eslint/config";
import eslintConfigPrettier from "eslint-config-prettier/flat";
import reactHooks from "eslint-plugin-react-hooks";
import reactRefresh from "eslint-plugin-react-refresh";
import globals from "globals";
import tseslint from "typescript-eslint";
export default defineConfig([
globalIgnores(["dist"]),
{
files: ["**/*.{ts,tsx}"],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
globals: globals.browser,
},
},
eslintConfigPrettier,
]);
<!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="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
{
"name": "my-app",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc --noEmit && vite build",
"preview": "vite preview",
"typecheck": "tsc --noEmit",
"test": "vitest run",
"lint": "eslint .",
"format": "prettier --write .",
"format:check": "prettier --check ."
},
"dependencies": {
"@tanstack/react-query": "^5.108.4",
"react": "^19.3.1",
"react-dom": "^19.3.1"
},
"devDependencies": {
"@eslint/js": "^10.0.1",
"@tailwindcss/vite": "^4.3.5",
"@testing-library/dom": "^10.4.2",
"@testing-library/jest-dom": "^8.0.0",
"@testing-library/react": "^16.3.3",
"@testing-library/user-event": "^14.6.13",
"@types/react": "^19.3.0",
"@types/react-dom": "^19.3.0",
"@vitejs/plugin-react": "^6.3.0",
"eslint": "^10.15.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-react-hooks": "^7.1.1",
"eslint-plugin-react-refresh": "^0.5.8",
"globals": "^17.14.0",
"jsdom": "^31.0.1",
"prettier": "^3.10.1",
"tailwindcss": "^4.3.5",
"typescript": "~6.0.3",
"typescript-eslint": "^8.74.0",
"vite": "^8.3.8",
"vitest": "^5.1.1"
}
}
[
"React 19",
"Vite",
"TypeScript",
"Tailwind CSS",
"TanStack Query",
"Express",
"MongoDB",
"Vitest",
"Testing Library",
"ESLint",
"Prettier"
]
# my-app
Stack: React 19, Vite, TypeScript, Tailwind CSS, TanStack Query, Express, MongoDB, Vitest, Testing Library, ESLint, Prettier.
## Getting started
```bash
npm install
npm run dev
```
## Scripts
- `npm run build`
- `npm run preview`
- `npm run typecheck`
- `npm run test`
- `npm run lint`
- `npm run format`
- `npm run format:check`
## 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
```
/** Loads the stack list served from `public/stack.json`. */
export async function fetchStack(): Promise<string[]> {
const response = await fetch(`${import.meta.env.BASE_URL}stack.json`);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
return response.json();
}
import ApiGreeting from "./components/ApiGreeting";
import Counter from "./components/Counter";
import StackList from "./components/StackList";
export default function App() {
return (
<main className="flex min-h-screen flex-col items-center justify-center gap-8 bg-slate-50 p-8 text-slate-900">
<h1 className="text-3xl font-bold tracking-tight">my-app</h1>
<Counter />
<StackList />
<ApiGreeting />
</main>
);
}
import { useEffect, useState } from "react";
export default function ApiGreeting() {
const [message, setMessage] = useState("Calling the API…");
useEffect(() => {
fetch("/api/hello?name=my-app")
.then((response) => {
if (!response.ok) throw new Error(`HTTP ${response.status}`);
return response.json();
})
.then((data) => setMessage(data.message))
.catch(() => setMessage("The API isn't running: start it in server/."));
}, []);
return <p className="max-w-md text-center text-slate-600">{message}</p>;
}
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { describe, expect, it } from "vitest";
import Counter from "./Counter";
describe("Counter", () => {
it("increments when +1 is clicked", async () => {
const user = userEvent.setup();
render(<Counter />);
await user.click(screen.getByRole("button", { name: "+1" }));
expect(screen.getByText("1")).toBeInTheDocument();
});
});
import { useState } from "react";
export default function Counter() {
const [count, setCount] = useState(0);
return (
<div className="rounded-2xl bg-white p-8 text-center shadow-sm ring-1 ring-slate-200">
<p className="text-5xl font-bold tabular-nums">{count}</p>
<div className="mt-6 flex justify-center gap-3">
<button
type="button"
className="rounded-lg bg-slate-900 px-4 py-2 text-white hover:bg-slate-700"
onClick={() => setCount((n) => n - 1)}
>
-1
</button>
<button
type="button"
className="rounded-lg bg-slate-900 px-4 py-2 text-white hover:bg-slate-700"
onClick={() => setCount((n) => n + 1)}
>
+1
</button>
</div>
</div>
);
}
import { useQuery } from "@tanstack/react-query";
import { fetchStack } from "../api/stack";
export default function StackList() {
const stack = useQuery({ queryKey: ["stack"], queryFn: fetchStack });
return (
<p className="max-w-md text-center text-slate-600">
{stack.isPending
? "Loading…"
: stack.isError
? "Could not load the stack."
: `Built with ${stack.data.join(", ")}.`}
</p>
);
}
@import "tailwindcss";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import App from "./App";
import "./index.css";
const queryClient = new QueryClient();
createRoot(document.getElementById("root")!).render(
<StrictMode>
<QueryClientProvider client={queryClient}>
<App />
</QueryClientProvider>
</StrictMode>,
);
import "@testing-library/jest-dom/vitest";
import { cleanup } from "@testing-library/react";
import { afterEach } from "vitest";
afterEach(() => {
cleanup();
});
{
"compilerOptions": {
"target": "ES2022",
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"moduleResolution": "bundler",
"jsx": "react-jsx",
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"isolatedModules": true,
"verbatimModuleSyntax": true,
"types": ["vite/client"]
},
"include": ["src", "vite.config.ts"]
}
/// <reference types="vitest/config" />
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";
export default defineConfig({
plugins: [react(), tailwindcss()],
server: { proxy: { "/api": "http://localhost:3001" } },
test: {
environment: "jsdom",
setupFiles: ["./src/test-setup.ts"],
},
});
Project files
README.mddocker-compose.ymlserver/.env.exampleserver/.gitignoreserver/README.mdserver/package.jsonserver/src/app.tsserver/src/db.tsserver/src/index.tsserver/src/models/todo.tsserver/tsconfig.jsonweb/.gitignoreweb/.prettierignoreweb/.prettierrcweb/README.mdweb/eslint.config.jsweb/index.htmlweb/package.jsonweb/public/stack.jsonweb/src/App.tsxweb/src/api/stack.tsweb/src/components/ApiGreeting.tsxweb/src/components/Counter.test.tsxweb/src/components/Counter.tsxweb/src/components/StackList.tsxweb/src/index.cssweb/src/main.tsxweb/src/test-setup.tsweb/tsconfig.jsonweb/vite.config.ts