mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
docs: more consistency + minor updates (#24764)
Co-authored-by: RiskyMH <git@riskymh.dev>
This commit is contained in:
@@ -26,4 +26,4 @@ const regularArr = Array.from(uintArr);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -23,4 +23,4 @@ blob.type; // => "application/octet-stream"
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -24,4 +24,4 @@ const nodeBuffer = Buffer.from(arrBuffer, 0, 16); // view first 16 bytes
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -14,4 +14,4 @@ const str = decoder.decode(buf);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -38,4 +38,4 @@ const arr = new Uint8Array(buffer, 0, 16); // view first 16 bytes
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils) for more useful utilities.
|
||||
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|
||||
|
||||
@@ -13,4 +13,4 @@ const buf = await blob.arrayBuffer();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const arr = new DataView(await blob.arrayBuffer());
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const stream = await blob.stream();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -14,4 +14,4 @@ const str = await blob.text();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const arr = new Uint8Array(await blob.arrayBuffer());
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const arrBuf = nodeBuf.buffer;
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const blob = new Blob([buf]);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -40,4 +40,4 @@ const stream = blob.stream(1024);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -24,4 +24,4 @@ const str = buf.toString("utf8", 0, 5);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ buf instanceof Uint8Array; // => true
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -14,4 +14,4 @@ const str = decoder.decode(dv);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -24,4 +24,4 @@ arr.byteLength; // => 32
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -15,4 +15,4 @@ console.log(await blob.text());
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const buf = Buffer.from(arr);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -13,4 +13,4 @@ const dv = new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -40,4 +40,4 @@ const stream = blob.stream(1024);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -15,4 +15,4 @@ const str = decoder.decode(arr);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Binary Data](https://bun.com/docs/api/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
See [Docs > API > Binary Data](/runtime/binary-data#conversion) for complete documentation on manipulating binary data with Bun.
|
||||
|
||||
@@ -4,8 +4,6 @@ sidebarTitle: Deploy on Vercel
|
||||
mode: center
|
||||
---
|
||||
|
||||
import { ProductCard } from "/snippets/product-card.mdx";
|
||||
|
||||
[Vercel](https://vercel.com/) is a cloud platform that lets you build, deploy, and scale your apps.
|
||||
|
||||
<Warning>
|
||||
|
||||
@@ -22,7 +22,7 @@ bun add discord.js
|
||||
|
||||
---
|
||||
|
||||
Before we go further, we need to go to the [Discord developer portal](https://discord.com/developers/applications), login/signup, create a new _Application_, then create a new _Bot_ within that application. Follow the [official guide](https://discordjs.guide/preparations/setting-up-a-bot-application.html#creating-your-bot) for step-by-step instructions.
|
||||
Before we go further, we need to go to the [Discord developer portal](https://discord.com/developers/applications), login/signup, create a new _Application_, then create a new _Bot_ within that application. Follow the [official guide](https://discordjs.guide/legacy/preparations/app-setup#creating-your-bot) for step-by-step instructions.
|
||||
|
||||
---
|
||||
|
||||
@@ -30,7 +30,7 @@ Once complete, you'll be presented with your bot's _private key_. Let's add this
|
||||
|
||||
<Note>This is an example token that has already been invalidated.</Note>
|
||||
|
||||
```txt .env.local icon="settings"
|
||||
```ini .env.local icon="settings"
|
||||
DISCORD_TOKEN=NzkyNzE1NDU0MTk2MDg4ODQy.X-hvzA.Ovy4MCQywSkoMRRclStW4xAYK7I
|
||||
```
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ mode: center
|
||||
Express and other major Node.js HTTP libraries should work out of the box. Bun implements the [`node:http`](https://nodejs.org/api/http.html) and [`node:https`](https://nodejs.org/api/https.html) modules that these libraries rely on.
|
||||
|
||||
<Note>
|
||||
Refer to the [Runtime > Node.js APIs](https://bun.com/docs/runtime/nodejs-apis#node-http) page for more detailed
|
||||
compatibility information.
|
||||
Refer to the [Runtime > Node.js APIs](/runtime/nodejs-compat#node-http) page for more detailed compatibility
|
||||
information.
|
||||
</Note>
|
||||
|
||||
```sh terminal icon="terminal"
|
||||
|
||||
@@ -89,4 +89,4 @@ Moo!
|
||||
|
||||
---
|
||||
|
||||
This is a simple introduction to using Mongoose with TypeScript and Bun. As you build your application, refer to the official [MongoDB](https://docs.mongodb.com/) and [Mongoose](https://mongoosejs.com/docs/) sites for complete documentation.
|
||||
This is a simple introduction to using Mongoose with TypeScript and Bun. As you build your application, refer to the official [MongoDB](https://www.mongodb.com/docs) and [Mongoose](https://mongoosejs.com/docs/) sites for complete documentation.
|
||||
|
||||
@@ -20,7 +20,7 @@ bun add -D drizzle-kit
|
||||
|
||||
Create a `.env.local` file and add your [Neon Postgres connection string](https://neon.tech/docs/connect/connect-from-any-app) to it.
|
||||
|
||||
```txt .env.local icon="settings"
|
||||
```ini .env.local icon="settings"
|
||||
DATABASE_URL=postgresql://usertitle:password@ep-adj-noun-guid.us-east-1.aws.neon.tech/neondb?sslmode=require
|
||||
```
|
||||
|
||||
@@ -33,7 +33,7 @@ import { neon } from "@neondatabase/serverless";
|
||||
import { drizzle } from "drizzle-orm/neon-http";
|
||||
|
||||
// Bun automatically loads the DATABASE_URL from .env.local
|
||||
// Refer to: https://bun.com/docs/runtime/env for more information
|
||||
// Refer to: https://bun.com/docs/runtime/environment-variables for more information
|
||||
const sql = neon(process.env.DATABASE_URL!);
|
||||
|
||||
export const db = drizzle(sql);
|
||||
|
||||
@@ -21,7 +21,7 @@ bun add @neondatabase/serverless
|
||||
|
||||
Create a `.env.local` file and add your [Neon Postgres connection string](https://neon.tech/docs/connect/connect-from-any-app) to it.
|
||||
|
||||
```sh .env.local icon="settings"
|
||||
```ini .env.local icon="settings"
|
||||
DATABASE_URL=postgresql://usertitle:password@ep-adj-noun-guid.us-east-1.aws.neon.tech/neondb?sslmode=require
|
||||
```
|
||||
|
||||
@@ -33,7 +33,7 @@ Paste the following code into your project's `index.ts` file.
|
||||
import { neon } from "@neondatabase/serverless";
|
||||
|
||||
// Bun automatically loads the DATABASE_URL from .env.local
|
||||
// Refer to: https://bun.com/docs/runtime/env for more information
|
||||
// Refer to: https://bun.com/docs/runtime/environment-variables for more information
|
||||
const sql = neon(process.env.DATABASE_URL);
|
||||
|
||||
const rows = await sql`SELECT version()`;
|
||||
|
||||
@@ -62,7 +62,7 @@ mode: center
|
||||
<Step title="Configure database connection">
|
||||
Set up your Postgres database URL in the `.env` file.
|
||||
|
||||
```env .env icon="settings"
|
||||
```ini .env icon="settings"
|
||||
DATABASE_URL="postgresql://username:password@localhost:5432/mydb?schema=public"
|
||||
```
|
||||
</Step>
|
||||
|
||||
@@ -161,4 +161,4 @@ mode: center
|
||||
|
||||
---
|
||||
|
||||
That's it! Now that you've set up Prisma using Bun, we recommend referring to the [official Prisma docs](https://www.prisma.io/docs/concepts/components/prisma-client) as you continue to develop your application.
|
||||
That's it! Now that you've set up Prisma using Bun, we recommend referring to the [official Prisma docs](https://www.prisma.io/docs/orm/prisma-client) as you continue to develop your application.
|
||||
|
||||
@@ -65,14 +65,14 @@ bun create qwik
|
||||
│ bun qwik add │
|
||||
│ │
|
||||
│ Relevant docs: │
|
||||
│ https://qwik.builder.io/docs/getting-started/ │
|
||||
│ https://qwik.dev/docs/getting-started/ │
|
||||
│ │
|
||||
│ Questions? Start the conversation at: │
|
||||
│ https://qwik.builder.io/chat │
|
||||
│ https://qwik.dev/chat │
|
||||
│ https://twitter.com/QwikDev │
|
||||
│ │
|
||||
│ Presentations, Podcasts and Videos: │
|
||||
│ https://qwik.builder.io/media/ │
|
||||
│ https://qwik.dev/media/ │
|
||||
│ │
|
||||
│ Next steps: │
|
||||
│ cd my-app │
|
||||
@@ -111,4 +111,4 @@ Open [http://localhost:5173](http://localhost:5173) with your browser to see the
|
||||
|
||||
---
|
||||
|
||||
Refer to the [Qwik docs](https://qwik.builder.io/docs/getting-started/) for complete documentation.
|
||||
Refer to the [Qwik docs](https://qwik.dev/docs/getting-started/) for complete documentation.
|
||||
|
||||
@@ -20,7 +20,7 @@ bun add @sentry/bun
|
||||
|
||||
Then, initialize the Sentry SDK with your Sentry DSN in your app's entry file. You can find your DSN in your Sentry project settings.
|
||||
|
||||
```js sentry.ts icon="/icons/typescript.svg"
|
||||
```ts sentry.ts icon="/icons/typescript.svg"
|
||||
import * as Sentry from "@sentry/bun";
|
||||
|
||||
// Ensure to call this before importing any other modules!
|
||||
@@ -37,7 +37,7 @@ Sentry.init({
|
||||
|
||||
You can verify that Sentry is working by capturing a test error:
|
||||
|
||||
```js sentry.ts icon="/icons/typescript.svg"
|
||||
```ts sentry.ts icon="/icons/typescript.svg"
|
||||
setTimeout(() => {
|
||||
try {
|
||||
foo();
|
||||
|
||||
@@ -88,7 +88,7 @@ To build for production, you'll need to add the right SvelteKit adapter. Current
|
||||
|
||||
Now, make the following changes to your `svelte.config.js`.
|
||||
|
||||
```ts svelte.config.js icon="file-code"
|
||||
```js svelte.config.js icon="file-code"
|
||||
import adapter from "@sveltejs/adapter-auto"; // [!code --]
|
||||
import adapter from "svelte-adapter-bun"; // [!code ++]
|
||||
import { vitePreprocess } from "@sveltejs/vite-plugin-svelte";
|
||||
|
||||
@@ -98,7 +98,6 @@ To host your TanStack Start app, you can use [Nitro](https://nitro.build/) or a
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<Note>
|
||||
You do **not** need the custom `start` script when deploying to Vercel.
|
||||
</Note>
|
||||
|
||||
@@ -34,7 +34,7 @@ mode: center
|
||||
|
||||
Set the `REDIS_URL` environment variable in your `.env` file using the Redis endpoint (not the REST URL):
|
||||
|
||||
```env .env icon="settings"
|
||||
```ini .env icon="settings"
|
||||
REDIS_URL=rediss://********@********.upstash.io:6379
|
||||
```
|
||||
|
||||
|
||||
@@ -74,4 +74,4 @@ bunx --bun vite build
|
||||
|
||||
---
|
||||
|
||||
This is a stripped down guide to get you started with Vite + Bun. For more information, see the [Vite documentation](https://vitejs.dev/guide/).
|
||||
This is a stripped down guide to get you started with Vite + Bun. For more information, see the [Vite documentation](https://vite.dev/guide/).
|
||||
|
||||
@@ -6,7 +6,7 @@ mode: center
|
||||
|
||||
## Extract links from a webpage
|
||||
|
||||
Bun's [HTMLRewriter](https://bun.com/docs/api/html-rewriter) API can be used to efficiently extract links from HTML content. It works by chaining together CSS selectors to match the elements, text, and attributes you want to process. This is a simple example of how to extract links from a webpage. You can pass `.transform` a `Response`, `Blob`, or `string`.
|
||||
Bun's [HTMLRewriter](/runtime/html-rewriter) API can be used to efficiently extract links from HTML content. It works by chaining together CSS selectors to match the elements, text, and attributes you want to process. This is a simple example of how to extract links from a webpage. You can pass `.transform` a `Response`, `Blob`, or `string`.
|
||||
|
||||
```ts extract-links.ts icon="/icons/typescript.svg"
|
||||
async function extractLinks(url: string) {
|
||||
@@ -68,4 +68,4 @@ const websiteLinks = await extractLinksFromURL("https://example.com");
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > HTMLRewriter](https://bun.com/docs/api/html-rewriter) for complete documentation on HTML transformation with Bun.
|
||||
See [Docs > API > HTMLRewriter](/runtime/html-rewriter) for complete documentation on HTML transformation with Bun.
|
||||
|
||||
@@ -6,7 +6,7 @@ mode: center
|
||||
|
||||
## Extract social share images and Open Graph tags
|
||||
|
||||
Bun's [HTMLRewriter](https://bun.com/docs/api/html-rewriter) API can be used to efficiently extract social share images and Open Graph metadata from HTML content. This is particularly useful for building link preview features, social media cards, or web scrapers. We can use HTMLRewriter to match CSS selectors to HTML elements, text, and attributes we want to process.
|
||||
Bun's [HTMLRewriter](/runtime/html-rewriter) API can be used to efficiently extract social share images and Open Graph metadata from HTML content. This is particularly useful for building link preview features, social media cards, or web scrapers. We can use HTMLRewriter to match CSS selectors to HTML elements, text, and attributes we want to process.
|
||||
|
||||
```ts extract-social-meta.ts icon="/icons/typescript.svg"
|
||||
interface SocialMetadata {
|
||||
|
||||
@@ -63,7 +63,7 @@ Our form will send a `POST` request to the `/action` endpoint with the form data
|
||||
|
||||
First we use the [`.formData()`](https://developer.mozilla.org/en-US/docs/Web/API/Request/formData) method on the incoming `Request` to asynchronously parse its contents to a `FormData` instance. Then we can use the [`.get()`](https://developer.mozilla.org/en-US/docs/Web/API/FormData/get) method to extract the value of the `name` and `profilePicture` fields. Here `name` corresponds to a `string` and `profilePicture` is a `Blob`.
|
||||
|
||||
Finally, we write the `Blob` to disk using [`Bun.write()`](https://bun.com/docs/api/file-io#writing-files-bun-write).
|
||||
Finally, we write the `Blob` to disk using [`Bun.write()`](/runtime/file-io#writing-files-bun-write).
|
||||
|
||||
{/* prettier-ignore */}
|
||||
```ts index.ts icon="/icons/typescript.svg"
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Hot reload an HTTP server
|
||||
mode: center
|
||||
---
|
||||
|
||||
Bun supports the [`--hot`](https://bun.com/docs/runtime/hot#hot-mode) flag to run a file with hot reloading enabled. When any module or file changes, Bun re-runs the file.
|
||||
Bun supports the [`--hot`](/runtime/watch-mode#hot-mode) flag to run a file with hot reloading enabled. When any module or file changes, Bun re-runs the file.
|
||||
|
||||
```sh terminal icon="terminal"
|
||||
bun --hot run index.ts
|
||||
|
||||
@@ -6,7 +6,7 @@ mode: center
|
||||
|
||||
This starts an HTTP server listening on port `3000`. It demonstrates basic routing with a number of common responses and also handles POST data from standard forms or as JSON.
|
||||
|
||||
See [`Bun.serve`](https://bun.com/docs/api/http) for details.
|
||||
See [`Bun.serve`](/runtime/http/server) for details.
|
||||
|
||||
```ts server.ts icon="/icons/typescript.svg"
|
||||
const server = Bun.serve({
|
||||
|
||||
@@ -6,7 +6,7 @@ mode: center
|
||||
|
||||
This starts an HTTP server listening on port `3000`. It responds to all requests with a `Response` with status `200` and body `"Welcome to Bun!"`.
|
||||
|
||||
See [`Bun.serve`](https://bun.com/docs/api/http) for details.
|
||||
See [`Bun.serve`](/runtime/http/server) for details.
|
||||
|
||||
```ts server.ts icon="/icons/typescript.svg"
|
||||
const server = Bun.serve({
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Stream file response
|
||||
mode: center
|
||||
---
|
||||
|
||||
This snippet reads a file from disk using [`Bun.file()`](https://bun.com/docs/api/file-io#reading-files-bun-file). This returns a `BunFile` instance, which can be passed directly into the `new Response` constructor.
|
||||
This snippet reads a file from disk using [`Bun.file()`](/runtime/file-io#reading-files-bun-file). This returns a `BunFile` instance, which can be passed directly into the `new Response` constructor.
|
||||
|
||||
```ts server.ts icon="/icons/typescript.svg"
|
||||
const path = "/path/to/file.txt";
|
||||
@@ -32,7 +32,7 @@ new Response(Bun.file("./img.png")).headers.get("Content-Type");
|
||||
|
||||
---
|
||||
|
||||
Putting it all together with [`Bun.serve()`](https://bun.com/docs/api/http#bun-serve).
|
||||
Putting it all together with [`Bun.serve()`](/runtime/http/server).
|
||||
|
||||
```ts server.ts icon="/icons/typescript.svg"
|
||||
// static file server
|
||||
@@ -47,4 +47,4 @@ Bun.serve({
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > File I/O](https://bun.com/docs/api/file-io#writing-files-bun-write) for complete documentation of `Bun.write()`.
|
||||
See [Docs > API > File I/O](/runtime/file-io#writing-files-bun-write) for complete documentation of `Bun.write()`.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Configure TLS
|
||||
mode: center
|
||||
---
|
||||
|
||||
Set the `tls` key to configure TLS. Both `key` and `cert` are required. The `key` should be the contents of your private key; `cert` should be the contents of your issued certificate. Use [`Bun.file()`](https://bun.com/docs/api/file-io#reading-files-bun-file) to read the contents.
|
||||
Set the `tls` key to configure TLS. Both `key` and `cert` are required. The `key` should be the contents of your private key; `cert` should be the contents of your issued certificate. Use [`Bun.file()`](/runtime/file-io#reading-files-bun-file) to read the contents.
|
||||
|
||||
```ts server.ts icon="/icons/typescript.svg"
|
||||
const server = Bun.serve({
|
||||
|
||||
@@ -25,4 +25,4 @@ This will add the package to `devDependencies` in `package.json`.
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -37,4 +37,4 @@ bun add github:colinhacks/zod
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -24,4 +24,4 @@ This will add the package to `optionalDependencies` in `package.json`.
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -42,4 +42,4 @@ Running `bun install` will install peer dependencies by default, unless marked o
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -32,4 +32,4 @@ import { z } from "zod";
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -41,4 +41,4 @@ bun add zod@next
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -31,9 +31,9 @@ password = "$NPM_PASSWORD"
|
||||
|
||||
---
|
||||
|
||||
Then assign your Azure Personal Access Token to the `NPM_PASSWORD` environment variable. Bun [automatically reads](https://bun.com/docs/runtime/env) `.env` files, so create a file called `.env` in your project root. There is no need to base-64 encode this token! Bun will do this for you.
|
||||
Then assign your Azure Personal Access Token to the `NPM_PASSWORD` environment variable. Bun [automatically reads](/runtime/environment-variables) `.env` files, so create a file called `.env` in your project root. There is no need to base-64 encode this token! Bun will do this for you.
|
||||
|
||||
```txt .env icon="settings"
|
||||
```ini .env icon="settings"
|
||||
NPM_PASSWORD=<paste token here>
|
||||
```
|
||||
|
||||
@@ -43,7 +43,7 @@ NPM_PASSWORD=<paste token here>
|
||||
|
||||
---
|
||||
|
||||
To configure Azure Artifacts without `bunfig.toml`, you can set the `NPM_CONFIG_REGISTRY` environment variable. The URL should include `:username` and `:_password` as query parameters. Replace `<USERNAME>` and `<PASSWORD>` with the apprropriate values.
|
||||
To configure Azure Artifacts without `bunfig.toml`, you can set the `NPM_CONFIG_REGISTRY` environment variable. The URL should include `:username` and `:_password` as query parameters. Replace `<USERNAME>` and `<PASSWORD>` with the appropriate values.
|
||||
|
||||
```bash terminal icon="terminal"
|
||||
NPM_CONFIG_REGISTRY=https://pkgs.dev.azure.com/my-azure-artifacts-user/_packaging/my-azure-artifacts-user/npm/registry/:username=<USERNAME>:_password=<PASSWORD>
|
||||
|
||||
@@ -20,7 +20,7 @@ registry = "https://usertitle:password@registry.npmjs.org"
|
||||
|
||||
---
|
||||
|
||||
Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](https://bun.com/docs/runtime/env) for more information.
|
||||
Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](/runtime/environment-variables) for more information.
|
||||
|
||||
```toml bunfig.toml icon="settings"
|
||||
[install]
|
||||
@@ -29,4 +29,4 @@ registry = { url = "https://registry.npmjs.org", token = "$npm_token" }
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -6,7 +6,8 @@ mode: center
|
||||
|
||||
<Note>
|
||||
Bun v1.1.39 introduced `bun.lock`, a JSONC formatted lockfile. `bun.lock` is human-readable and git-diffable without
|
||||
configuration, at no cost to performance. [**Learn more.**](https://bun.com/docs/install/lockfile#text-based-lockfile)
|
||||
configuration, at no cost to performance. In 1.2.0+ it is the default format used for new projects. [**Learn
|
||||
more.**](/pm/lockfile#text-based-lockfile)
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
@@ -22,4 +22,4 @@ z.string();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Configure a scoped registry
|
||||
mode: center
|
||||
---
|
||||
|
||||
Private registries can be configured using either [`.npmrc`](https://bun.com/docs/install/npmrc) or [`bunfig.toml`](https://bun.com/docs/runtime/bunfig#install-registry). While both are supported, we recommend using **bunfig.toml** for enhanced flexibility and Bun-specific options.
|
||||
Private registries can be configured using either [`.npmrc`](/pm/npmrc) or [`bunfig.toml`](/runtime/bunfig#install-registry). While both are supported, we recommend using **bunfig.toml** for enhanced flexibility and Bun-specific options.
|
||||
|
||||
To configure a registry for a particular npm scope:
|
||||
|
||||
@@ -28,7 +28,7 @@ To configure a registry for a particular npm scope:
|
||||
|
||||
---
|
||||
|
||||
Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](https://bun.com/docs/runtime/env) for more information.
|
||||
Your `bunfig.toml` can reference environment variables. Bun automatically loads environment variables from `.env.local`, `.env.[NODE_ENV]`, and `.env`. See [Docs > Environment variables](/runtime/environment-variables) for more information.
|
||||
|
||||
```toml bunfig.toml icon="settings"
|
||||
[install.scopes]
|
||||
@@ -37,4 +37,4 @@ Your `bunfig.toml` can reference environment variables. Bun automatically loads
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -47,4 +47,4 @@ bun install
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager > Trusted dependencies](https://bun.com/docs/install/lifecycle) for complete documentation of trusted dependencies.
|
||||
See [Docs > Package manager > Trusted dependencies](/pm/lifecycle) for complete documentation of trusted dependencies.
|
||||
|
||||
@@ -67,4 +67,4 @@ bun add zod
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -6,12 +6,13 @@ mode: center
|
||||
|
||||
<Note>
|
||||
Bun v1.1.39 introduced `bun.lock`, a JSONC formatted lockfile. `bun.lock` is human-readable and git-diffable without
|
||||
configuration, at no cost to performance. [**Learn more.**](https://bun.com/docs/install/lockfile#text-based-lockfile)
|
||||
configuration, at no cost to performance. In 1.2.0+ it is the default format used for new projects. [**Learn
|
||||
more.**](/pm/lockfile#text-based-lockfile)
|
||||
</Note>
|
||||
|
||||
---
|
||||
|
||||
Use the `--yarn` flag to generate a Yarn-compatible `yarn.lock` file (in addition to `bun.lock`).
|
||||
Use the `--yarn` flag to generate a Yarn-compatible `yarn.lock` file (in addition to `bun.lock{b}`).
|
||||
|
||||
```sh terminal icon="terminal"
|
||||
bun install --yarn
|
||||
@@ -47,4 +48,4 @@ abab@^2.0.6:
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](https://bun.com/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
See [Docs > Package manager](/pm/cli/install) for complete documentation of Bun's package manager.
|
||||
|
||||
@@ -15,4 +15,4 @@ process.on("SIGINT", () => {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils) for more useful utilities.
|
||||
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Spawn a child process and communicate using IPC
|
||||
mode: center
|
||||
---
|
||||
|
||||
Use [`Bun.spawn()`](https://bun.com/docs/api/spawn) to spawn a child process. When spawning a second `bun` process, you can open a direct inter-process communication (IPC) channel between the two processes.
|
||||
Use [`Bun.spawn()`](/runtime/child-process) to spawn a child process. When spawning a second `bun` process, you can open a direct inter-process communication (IPC) channel between the two processes.
|
||||
|
||||
<Note>
|
||||
This API is only compatible with other `bun` processes. Use `process.execPath` to get a path to the currently running
|
||||
@@ -66,4 +66,4 @@ process.send({ message: "Hello from child as object" });
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](https://bun.com/docs/api/spawn) for complete documentation.
|
||||
See [Docs > API > Child processes](/runtime/child-process) for complete documentation.
|
||||
|
||||
@@ -12,4 +12,4 @@ Bun.nanoseconds();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils) for more useful utilities.
|
||||
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|
||||
|
||||
@@ -38,4 +38,4 @@ process.on("exit", code => {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils) for more useful utilities.
|
||||
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Read stderr
|
||||
mode: center
|
||||
---
|
||||
|
||||
When using [`Bun.spawn()`](https://bun.com/docs/api/spawn), the child process inherits the `stderr` of the spawning process. If instead you'd prefer to read and handle `stderr`, set the `stderr` option to `"pipe"`.
|
||||
When using [`Bun.spawn()`](/runtime/child-process), the child process inherits the `stderr` of the spawning process. If instead you'd prefer to read and handle `stderr`, set the `stderr` option to `"pipe"`.
|
||||
|
||||
```ts
|
||||
const proc = Bun.spawn(["echo", "hello"], {
|
||||
@@ -31,4 +31,4 @@ if (errors) {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](https://bun.com/docs/api/spawn) for complete documentation.
|
||||
See [Docs > API > Child processes](/runtime/child-process) for complete documentation.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Read stdout
|
||||
mode: center
|
||||
---
|
||||
|
||||
When using [`Bun.spawn()`](https://bun.com/docs/api/spawn), the `stdout` of the child process can be consumed as a `ReadableStream` via `proc.stdout`.
|
||||
When using [`Bun.spawn()`](/runtime/child-process), the `stdout` of the child process can be consumed as a `ReadableStream` via `proc.stdout`.
|
||||
|
||||
```ts
|
||||
const proc = Bun.spawn(["echo", "hello"]);
|
||||
@@ -25,4 +25,4 @@ const proc = Bun.spawn(["echo", "hello"], {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](https://bun.com/docs/api/spawn) for complete documentation.
|
||||
See [Docs > API > Child processes](/runtime/child-process) for complete documentation.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Spawn child process
|
||||
mode: center
|
||||
---
|
||||
|
||||
Use [`Bun.spawn()`](https://bun.com/docs/api/spawn) to spawn a child process.
|
||||
Use [`Bun.spawn()`](/runtime/child-process) to spawn a child process.
|
||||
|
||||
```ts
|
||||
const proc = Bun.spawn(["echo", "hello"]);
|
||||
@@ -40,4 +40,4 @@ output; // => "hello\n"
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](https://bun.com/docs/api/spawn) for complete documentation.
|
||||
See [Docs > API > Child processes](/runtime/child-process) for complete documentation.
|
||||
|
||||
@@ -59,4 +59,4 @@ Chunk: hello
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils) for more useful utilities.
|
||||
See [Docs > API > Utils](/runtime/utils) for more useful utilities.
|
||||
|
||||
@@ -15,7 +15,7 @@ const buffer = await file.arrayBuffer();
|
||||
|
||||
---
|
||||
|
||||
The binary content in the `ArrayBuffer` can then be read as a typed array, such as `Int8Array`. For `Uint8Array`, use [`.bytes()`](./uint8array).
|
||||
The binary content in the `ArrayBuffer` can then be read as a typed array, such as `Int8Array`. For `Uint8Array`, use [`.bytes()`](/guides/read-file/uint8array).
|
||||
|
||||
```ts index.ts icon="/icons/typescript.svg"
|
||||
const buffer = await file.arrayBuffer();
|
||||
@@ -27,4 +27,4 @@ bytes.length;
|
||||
|
||||
---
|
||||
|
||||
Refer to the [Typed arrays](https://bun.com/docs/api/binary-data#typedarray) docs for more information on working with typed arrays in Bun.
|
||||
Refer to the [Typed arrays](/runtime/binary-data#typedarray) docs for more information on working with typed arrays in Bun.
|
||||
|
||||
@@ -18,4 +18,4 @@ const buffer = Buffer.from(arrbuf);
|
||||
|
||||
---
|
||||
|
||||
Refer to [Binary data > Buffer](https://bun.com/docs/api/binary-data#buffer) for more information on working with `Buffer` and other binary data formats in Bun.
|
||||
Refer to [Binary data > Buffer](/runtime/binary-data#buffer) for more information on working with `Buffer` and other binary data formats in Bun.
|
||||
|
||||
@@ -15,4 +15,4 @@ await file.exists(); // boolean;
|
||||
|
||||
---
|
||||
|
||||
Refer to [API > File I/O](https://bun.com/docs/api/file-io) for more information on working with `BunFile`.
|
||||
Refer to [API > File I/O](/runtime/file-io) for more information on working with `BunFile`.
|
||||
|
||||
@@ -19,4 +19,4 @@ file.type; // image/png
|
||||
|
||||
---
|
||||
|
||||
Refer to [API > File I/O](https://bun.com/docs/api/file-io) for more information on working with `BunFile`.
|
||||
Refer to [API > File I/O](/runtime/file-io) for more information on working with `BunFile`.
|
||||
|
||||
@@ -25,4 +25,4 @@ for await (const chunk of stream) {
|
||||
|
||||
---
|
||||
|
||||
Refer to the [Streams](https://bun.com/docs/api/streams) documentation for more information on working with streams in Bun.
|
||||
Refer to the [Streams](/runtime/streams) documentation for more information on working with streams in Bun.
|
||||
|
||||
@@ -20,4 +20,4 @@ byteArray.length; // length of byteArray
|
||||
|
||||
---
|
||||
|
||||
Refer to [API > Binary data > Typed arrays](https://bun.com/docs/api/binary-data#typedarray) for more information on working with `Uint8Array` and other binary data formats in Bun.
|
||||
Refer to [API > Binary data > Typed arrays](/runtime/binary-data#typedarray) for more information on working with `Uint8Array` and other binary data formats in Bun.
|
||||
|
||||
@@ -63,4 +63,4 @@ process.on("SIGINT", () => {
|
||||
|
||||
---
|
||||
|
||||
Refer to [API > Binary data > Typed arrays](https://bun.com/docs/api/binary-data#typedarray) for more information on working with `Uint8Array` and other binary data formats in Bun.
|
||||
Refer to [API > Binary data > Typed arrays](/runtime/binary-data#typedarray) for more information on working with `Uint8Array` and other binary data formats in Bun.
|
||||
|
||||
@@ -37,7 +37,7 @@ jobs:
|
||||
# ...
|
||||
- uses: oven-sh/setup-bun@v2
|
||||
with: # [!code ++]
|
||||
bun-version: 1.2.0 # or "latest", "canary", <sha> # [!code ++]
|
||||
bun-version: 1.3.2 # or "latest", "canary", <sha> # [!code ++]
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
@@ -36,4 +36,4 @@ try {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > FileSystem](https://bun.com/docs/api/file-io) for more filesystem operations.
|
||||
See [Docs > API > FileSystem](/runtime/file-io) for more filesystem operations.
|
||||
|
||||
@@ -18,4 +18,4 @@ const exists = await file.exists();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > FileSystem](https://bun.com/docs/api/file-io) for more filesystem operations.
|
||||
See [Docs > API > FileSystem](/runtime/file-io) for more filesystem operations.
|
||||
|
||||
@@ -43,4 +43,4 @@ data.author.name; // => "John Dough"
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Runtime > TypeScript](https://bun.com/docs/runtime/typescript) for more information on using TypeScript with Bun.
|
||||
See [Docs > Runtime > TypeScript](/runtime/typescript) for more information on using TypeScript with Bun.
|
||||
|
||||
@@ -29,4 +29,4 @@ data.author.name; // => "John Dough"
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Runtime > TypeScript](https://bun.com/docs/runtime/typescript) for more information on using TypeScript with Bun.
|
||||
See [Docs > Runtime > TypeScript](/runtime/typescript) for more information on using TypeScript with Bun.
|
||||
|
||||
@@ -101,4 +101,4 @@ export = contents;
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > YAML](https://bun.com/docs/api/yaml) for complete documentation on YAML support in Bun.
|
||||
See [Docs > API > YAML](/runtime/yaml) for complete documentation on YAML support in Bun.
|
||||
|
||||
@@ -34,4 +34,4 @@ FOOBAR=aaaaaa
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Runtime > Environment variables](https://bun.com/docs/runtime/env) for more information on using environment variables with Bun.
|
||||
See [Docs > Runtime > Environment variables](/runtime/environment-variables) for more information on using environment variables with Bun.
|
||||
|
||||
@@ -21,7 +21,7 @@ Bun reads the following files automatically (listed in order of increasing prece
|
||||
- `.env.production`, `.env.development`, `.env.test` (depending on value of `NODE_ENV`)
|
||||
- `.env.local` (not loaded when `NODE_ENV=test`)
|
||||
|
||||
```txt .env icon="settings"
|
||||
```ini .env icon="settings"
|
||||
FOO=hello
|
||||
BAR=world
|
||||
```
|
||||
@@ -48,4 +48,4 @@ $env:FOO="helloworld"; bun run dev
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Runtime > Environment variables](https://bun.com/docs/runtime/env) for more information on using environment variables with Bun.
|
||||
See [Docs > Runtime > Environment variables](/runtime/environment-variables) for more information on using environment variables with Bun.
|
||||
|
||||
@@ -39,4 +39,4 @@ for await (const line of $`ls -l`.lines()) {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Shell](https://bun.com/docs/runtime/shell) for complete documentation.
|
||||
See [Docs > API > Shell](/runtime/shell) for complete documentation.
|
||||
|
||||
@@ -28,4 +28,4 @@ import { Button } from "@components/Button"; // imports from "./src/components/B
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Runtime > TypeScript](https://bun.com/docs/runtime/typescript) for more information on using TypeScript with Bun.
|
||||
See [Docs > Runtime > TypeScript](/runtime/typescript) for more information on using TypeScript with Bun.
|
||||
|
||||
@@ -48,4 +48,4 @@ Below is the full set of recommended `compilerOptions` for a Bun project. With t
|
||||
|
||||
---
|
||||
|
||||
Refer to [Ecosystem > TypeScript](https://bun.com/docs/runtime/typescript) for a complete guide to TypeScript support in Bun.
|
||||
Refer to [Ecosystem > TypeScript](/runtime/typescript) for a complete guide to TypeScript support in Bun.
|
||||
|
||||
@@ -5,8 +5,7 @@ mode: center
|
||||
---
|
||||
|
||||
<Note>
|
||||
VSCode extension support is currently buggy. We recommend the [Web
|
||||
Debugger](https://bun.com/guides/runtime/web-debugger) for now.
|
||||
VSCode extension support is currently buggy. We recommend the [Web Debugger](/guides/runtime/web-debugger) for now.
|
||||
</Note>
|
||||
|
||||
Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-inspector-protocol/src/protocol/jsc/index.d.ts) so you can debug your code with an interactive debugger.
|
||||
|
||||
@@ -4,7 +4,7 @@ sidebarTitle: Web debugger
|
||||
mode: center
|
||||
---
|
||||
|
||||
Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-vscode/types/jsc.d.ts). To enable debugging when running code with Bun, use the `--inspect` flag. For demonstration purposes, consider the following simple web server.
|
||||
Bun speaks the [WebKit Inspector Protocol](https://github.com/oven-sh/bun/blob/main/packages/bun-inspector-protocol/src/protocol/jsc/index.d.ts). To enable debugging when running code with Bun, use the `--inspect` flag. For demonstration purposes, consider the following simple web server.
|
||||
|
||||
```ts server.ts icon="/icons/typescript.svg"
|
||||
Bun.serve({
|
||||
|
||||
@@ -13,4 +13,4 @@ const str = await Bun.readableStreamToArray(stream);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -13,4 +13,4 @@ const buf = await Bun.readableStreamToArrayBuffer(stream);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -13,4 +13,4 @@ const blob = await Bun.readableStreamToBlob(stream);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -14,4 +14,4 @@ const nodeBuf = Buffer.from(arrBuf);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -13,4 +13,4 @@ const json = await stream.json();
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -13,4 +13,4 @@ const str = await Bun.readableStreamToText(stream);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -21,4 +21,4 @@ const uint8 = await Bun.readableStreamToBytes(stream);
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Utils](https://bun.com/docs/api/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
See [Docs > API > Utils](/runtime/utils#bun-readablestreamto) for documentation on Bun's other `ReadableStream` conversion functions.
|
||||
|
||||
@@ -21,4 +21,4 @@ bun test --bail=10
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Test runner](https://bun.sh/docs/cli/test) for complete documentation of `bun test`.
|
||||
See [Docs > Test runner](/test) for complete documentation of `bun test`.
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
title: Selectively run tests concurrently with glob patterns
|
||||
sidebarTitle: Concurrent test glob
|
||||
mode: center
|
||||
description: Set a glob pattern to decide which tests from which files run in parallel
|
||||
---
|
||||
|
||||
This guide demonstrates how to use the `concurrentTestGlob` option to selectively run tests concurrently based on file naming patterns.
|
||||
@@ -69,12 +70,14 @@ test("fetch user data", async () => {
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
test("fetch posts", async () => {
|
||||
// can also use test.concurrent() for explicitly marking it as concurrent
|
||||
test.concurrent("fetch posts", async () => {
|
||||
const response = await fetch("/api/posts");
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
test("fetch comments", async () => {
|
||||
// can also use test.serial() for explicitly marking it as sequential
|
||||
test.serial("fetch comments", async () => {
|
||||
const response = await fetch("/api/comments");
|
||||
expect(response.ok).toBe(true);
|
||||
});
|
||||
|
||||
@@ -64,4 +64,4 @@ coverageThreshold = { lines = 0.5, functions = 0.7 }
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Test runner > Coverage](https://bun.sh/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
|
||||
See [Docs > Test runner > Coverage](/test/code-coverage) for complete documentation on code coverage reporting in Bun.
|
||||
|
||||
@@ -46,4 +46,4 @@ coverage = true # always enable coverage
|
||||
|
||||
---
|
||||
|
||||
Refer to [Docs > Test runner > Coverage](https://bun.sh/docs/test/coverage) for complete documentation on code coverage reporting in Bun.
|
||||
Refer to [Docs > Test runner > Coverage](/test/code-coverage) for complete documentation on code coverage reporting in Bun.
|
||||
|
||||
@@ -70,4 +70,4 @@ Ran 1 tests across 1 files. 1 total [125.00ms]
|
||||
|
||||
---
|
||||
|
||||
Refer to the [Happy DOM repo](https://github.com/capricorn86/happy-dom) and [Docs > Test runner > DOM](https://bun.sh/docs/test/dom) for complete documentation on writing browser tests with Bun.
|
||||
Refer to the [Happy DOM repo](https://github.com/capricorn86/happy-dom) and [Docs > Test runner > DOM](/test/dom) for complete documentation on writing browser tests with Bun.
|
||||
|
||||
@@ -62,7 +62,7 @@ describe("my test suite", () => {
|
||||
|
||||
---
|
||||
|
||||
Bun implements the vast majority of Jest's matchers, but compatibility isn't 100% yet. Refer to the full compatibility table at [Docs > Test runner > Writing tests](https://bun.sh/docs/test/writing#matchers).
|
||||
Bun implements the vast majority of Jest's matchers, but compatibility isn't 100% yet. Refer to the full compatibility table at [Docs > Test runner > Writing tests](/test/writing-tests#matchers).
|
||||
|
||||
Some notable missing features:
|
||||
|
||||
@@ -74,7 +74,7 @@ If you're using `testEnvironment: "jsdom"` to run your tests in a browser-like e
|
||||
|
||||
At the moment jsdom does not work in Bun due to its internal use of V8 APIs. Track support for it [here](https://github.com/oven-sh/bun/issues/3554).
|
||||
|
||||
```toml bunfig.toml
|
||||
```toml bunfig.toml icon="settings"
|
||||
[test]
|
||||
preload = ["./happy-dom.ts"]
|
||||
```
|
||||
@@ -107,11 +107,11 @@ bun test --timeout 10000
|
||||
|
||||
Many other flags become irrelevant or obsolete when using `bun test`.
|
||||
|
||||
- `transform` — Bun supports TypeScript & JSX. Other file types can be configured with [Plugins](https://bun.sh/docs/runtime/plugins).
|
||||
- `transform` — Bun supports TypeScript & JSX. Other file types can be configured with [Plugins](/runtime/plugins).
|
||||
- `extensionsToTreatAsEsm`
|
||||
- `haste` — Bun uses it's own internal source maps
|
||||
- `watchman`, `watchPlugins`, `watchPathIgnorePatterns` — use `--watch` to run tests in watch mode
|
||||
- `verbose` — set `logLevel: "debug"` in [`bunfig.toml`](https://bun.sh/docs/runtime/bunfig#loglevel)
|
||||
- `verbose` — set `logLevel: "debug"` in [`bunfig.toml`](/runtime/bunfig#loglevel)
|
||||
|
||||
---
|
||||
|
||||
@@ -122,4 +122,4 @@ Settings that aren't mentioned here are not supported or have no equivalent. Ple
|
||||
See also:
|
||||
|
||||
- [Mark a test as a todo](/guides/test/todo-tests)
|
||||
- [Docs > Test runner > Writing tests](https://bun.sh/docs/test/writing)
|
||||
- [Docs > Test runner > Writing tests](/test/writing-tests)
|
||||
|
||||
@@ -22,7 +22,7 @@ test("party like it's 1999", () => {
|
||||
|
||||
---
|
||||
|
||||
The `setSystemTime` function is commonly used on conjunction with [Lifecycle Hooks](https://bun.sh/docs/test/lifecycle) to configure a testing environment with a deterministic "fake clock".
|
||||
The `setSystemTime` function is commonly used on conjunction with [Lifecycle Hooks](/test/lifecycle) to configure a testing environment with a deterministic "fake clock".
|
||||
|
||||
```ts
|
||||
import { test, expect, beforeAll, setSystemTime } from "bun:test";
|
||||
@@ -47,4 +47,4 @@ setSystemTime(); // reset to actual time
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Test Runner > Date and time](https://bun.sh/docs/test/time) for complete documentation on mocking with the Bun test runner.
|
||||
See [Docs > Test Runner > Date and time](/test/dates-times) for complete documentation on mocking with the Bun test runner.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user