···11+22+Default to using Bun instead of Node.js.
33+44+- Use `bun <file>` instead of `node <file>` or `ts-node <file>`
55+- Use `bun test` instead of `jest` or `vitest`
66+- Use `bun build <file.html|file.ts|file.css>` instead of `webpack` or `esbuild`
77+- Use `bun install` instead of `npm install` or `yarn install` or `pnpm install`
88+- Use `bun run <script>` instead of `npm run <script>` or `yarn run <script>` or `pnpm run <script>`
99+- Bun automatically loads .env, so don't use dotenv.
1010+1111+## APIs
1212+1313+- `Bun.serve()` supports WebSockets, HTTPS, and routes. Don't use `express`.
1414+- `bun:sqlite` for SQLite. Don't use `better-sqlite3`.
1515+- `Bun.redis` for Redis. Don't use `ioredis`.
1616+- `Bun.sql` for Postgres. Don't use `pg` or `postgres.js`.
1717+- `WebSocket` is built-in. Don't use `ws`.
1818+- Prefer `Bun.file` over `node:fs`'s readFile/writeFile
1919+- Bun.$`ls` instead of execa.
2020+2121+## Testing
2222+2323+Use `bun test` to run tests.
2424+2525+```ts#index.test.ts
2626+import { test, expect } from "bun:test";
2727+2828+test("hello world", () => {
2929+ expect(1).toBe(1);
3030+});
3131+```
3232+3333+## Frontend
3434+3535+Use HTML imports with `Bun.serve()`. Don't use `vite`. HTML imports fully support React, CSS, Tailwind.
3636+3737+Server:
3838+3939+```ts#index.ts
4040+import index from "./index.html"
4141+4242+Bun.serve({
4343+ routes: {
4444+ "/": index,
4545+ "/api/users/:id": {
4646+ GET: (req) => {
4747+ return new Response(JSON.stringify({ id: req.params.id }));
4848+ },
4949+ },
5050+ },
5151+ // optional websocket support
5252+ websocket: {
5353+ open: (ws) => {
5454+ ws.send("Hello, world!");
5555+ },
5656+ message: (ws, message) => {
5757+ ws.send(message);
5858+ },
5959+ close: (ws) => {
6060+ // handle close
6161+ }
6262+ },
6363+ development: {
6464+ hmr: true,
6565+ console: true,
6666+ }
6767+})
6868+```
6969+7070+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.
7171+7272+```html#index.html
7373+<html>
7474+ <body>
7575+ <h1>Hello, world!</h1>
7676+ <script type="module" src="./frontend.tsx"></script>
7777+ </body>
7878+</html>
7979+```
8080+8181+With the following `frontend.tsx`:
8282+8383+```tsx#frontend.tsx
8484+import React from "react";
8585+8686+// import .css files directly and it works
8787+import './index.css';
8888+8989+import { createRoot } from "react-dom/client";
9090+9191+const root = createRoot(document.body);
9292+9393+export default function Frontend() {
9494+ return <h1>Hello, world!</h1>;
9595+}
9696+9797+root.render(<Frontend />);
9898+```
9999+100100+Then, run index.ts
101101+102102+```sh
103103+bun --hot ./index.ts
104104+```
105105+106106+For more information, read the Bun API docs in `node_modules/bun-types/docs/**.md`.