···1+2+Default to using Bun instead of Node.js.
3+4+- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
5+- Use `bun test` instead of `jest` or `vitest`
6+- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
7+- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
8+- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
9+- Bun automatically loads .env, so don't use dotenv.
10+11+## APIs
12+13+- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
14+- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
15+- `Bun.redis` for Redis. Don't use `ioredis`.
16+- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
17+- `WebSocket` is built-in. Don't use `ws`.
18+- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
19+- Bun.$`ls` instead of execa.
20+21+## Testing
22+23+Use `bun test` to run tests.
24+25+```ts#index.test.ts
26+import { test, expect } from "bun:test";
27+28+test("hello world", () => {
29+ expect(1).toBe(1);
30+});
31+```
32+33+## Frontend
34+35+Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
36+37+Server:
38+39+```ts#index.ts
40+import index from "./index.html"
41+42+Bun.serve({
43+ routes: {
44+ "/": index,
45+ "/api/users/:id": {
46+ GET: (req) => {
47+ return new Response(JSON.stringify({ id: req.params.id }));
48+ },
49+ },
50+ },
51+ // optional websocket support
52+ websocket: {
53+ open: (ws) => {
54+ ws.send("Hello, world!");
55+ },
56+ message: (ws, message) => {
57+ ws.send(message);
58+ },
59+ close: (ws) => {
60+ // handle close
61+ }
62+ },
63+ development: {
64+ hmr: true,
65+ console: true,
66+ }
67+})
68+```
69+70+HTML files can import .tsx, .jsx or .js files directly and Bun's bundler will transpile & bundle automatically. `<link>` tags can point to stylesheets and Bun's CSS bundler will bundle.
71+72+```html#index.html
73+<html>
74+ <body>
75+ <h1>Hello, world!</h1>
76+ <script type="module" src="./frontend.tsx"></script>
77+ </body>
78+</html>
79+```
80+81+With the following `frontend.tsx`:
82+83+```tsx#frontend.tsx
84+import React from "react";
85+86+// import .css files directly and it works
87+import './index.css';
88+89+import { createRoot } from "react-dom/client";
90+91+const root = createRoot(document.body);
92+93+export default function Frontend() {
94+ return <h1>Hello, world!</h1>;
95+}
96+97+root.render(<Frontend />);
98+```
99+100+Then, run index.ts
101+102+```sh
103+bun --hot ./index.ts
104+```
105+106+For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.