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:
@@ -54,7 +54,7 @@ Bun supports Linux (x64 & arm64), macOS (x64 & Apple Silicon) and Windows (x64).
|
||||
curl -fsSL https://bun.com/install | bash
|
||||
|
||||
# on windows
|
||||
powershell -c "irm bun.com/install.ps1 | iex"
|
||||
powershell -c "irm bun.sh/install.ps1 | iex"
|
||||
|
||||
# with npm
|
||||
npm install -g bun
|
||||
@@ -104,13 +104,13 @@ bun upgrade --canary
|
||||
- [File types (Loaders)](https://bun.com/docs/runtime/loaders)
|
||||
- [TypeScript](https://bun.com/docs/runtime/typescript)
|
||||
- [JSX](https://bun.com/docs/runtime/jsx)
|
||||
- [Environment variables](https://bun.com/docs/runtime/env)
|
||||
- [Environment variables](https://bun.com/docs/runtime/environment-variables)
|
||||
- [Bun APIs](https://bun.com/docs/runtime/bun-apis)
|
||||
- [Web APIs](https://bun.com/docs/runtime/web-apis)
|
||||
- [Node.js compatibility](https://bun.com/docs/runtime/nodejs-apis)
|
||||
- [Node.js compatibility](https://bun.com/docs/runtime/nodejs-compat)
|
||||
- [Single-file executable](https://bun.com/docs/bundler/executables)
|
||||
- [Plugins](https://bun.com/docs/runtime/plugins)
|
||||
- [Watch mode / Hot Reloading](https://bun.com/docs/runtime/hot)
|
||||
- [Watch mode / Hot Reloading](https://bun.com/docs/runtime/watch-mode)
|
||||
- [Module resolution](https://bun.com/docs/runtime/modules)
|
||||
- [Auto-install](https://bun.com/docs/runtime/autoimport)
|
||||
- [bunfig.toml](https://bun.com/docs/runtime/bunfig)
|
||||
|
||||
@@ -72,7 +72,7 @@ Bun's CSS bundler automatically converts this nested syntax into traditional fla
|
||||
|
||||
You can also nest media queries and other at-rules inside selectors, eliminating the need to repeat selector patterns:
|
||||
|
||||
```css title="styles.css" icon="file-code"
|
||||
```scss title="styles.css" icon="file-code"
|
||||
.responsive-element {
|
||||
display: block;
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ These constants are embedded directly into your compiled binary at build time, p
|
||||
|
||||
<Note>
|
||||
For comprehensive examples and advanced patterns, see the [Build-time constants
|
||||
guide](https://bun.com/guides/runtime/build-time-constants).
|
||||
guide](/guides/runtime/build-time-constants).
|
||||
</Note>
|
||||
|
||||
---
|
||||
@@ -288,12 +288,12 @@ console.log(`Server running at http://localhost:${server.port}`);
|
||||
</head>
|
||||
<body>
|
||||
<h1>Hello World</h1>
|
||||
<script src="./app.js"></script>
|
||||
<script src="./app.ts"></script>
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
```ts app.js icon="file-code"
|
||||
```ts app.ts icon="file-code"
|
||||
console.log("Hello from the client!");
|
||||
```
|
||||
|
||||
|
||||
@@ -632,7 +632,7 @@ const server = serve({
|
||||
console.log(`🚀 Server running on ${server.url}`);
|
||||
```
|
||||
|
||||
```html title="public/index.html"
|
||||
```html title="public/index.html" icon="file-code"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
@@ -757,7 +757,7 @@ export function App() {
|
||||
}
|
||||
```
|
||||
|
||||
```css title="src/styles.css"
|
||||
```css title="src/styles.css" icon="file-code"
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
@@ -999,7 +999,7 @@ CMD ["bun", "index.js"]
|
||||
|
||||
### Environment Variables
|
||||
|
||||
```bash title=".env.production" icon="file-code"
|
||||
```ini title=".env.production" icon="file-code"
|
||||
NODE_ENV=production
|
||||
PORT=3000
|
||||
DATABASE_URL=postgresql://user:pass@localhost:5432/myapp
|
||||
|
||||
@@ -9,7 +9,7 @@ Hot Module Replacement (HMR) allows you to update modules in a running applicati
|
||||
|
||||
## `import.meta.hot` API Reference
|
||||
|
||||
Bun implements a client-side HMR API modeled after [Vite's `import.meta.hot` API](https://vitejs.dev/guide/api-hmr.html). It can be checked for with `if (import.meta.hot)`, tree-shaking it in production.
|
||||
Bun implements a client-side HMR API modeled after [Vite's `import.meta.hot` API](https://vite.dev/guide/api-hmr). It can be checked for with `if (import.meta.hot)`, tree-shaking it in production.
|
||||
|
||||
```ts title="index.ts" icon="/icons/typescript.svg"
|
||||
if (import.meta.hot) {
|
||||
@@ -144,7 +144,7 @@ Indicates that multiple dependencies' modules can be accepted. This variant acce
|
||||
|
||||
`import.meta.hot.data` maintains state between module instances during hot replacement, enabling data transfer from previous to new versions. When `import.meta.hot.data` is written into, Bun will also mark this module as capable of self-accepting (equivalent of calling `import.meta.hot.accept()`).
|
||||
|
||||
```jsx title="index.ts" icon="/icons/typescript.svg"
|
||||
```tsx title="index.tsx" icon="/icons/typescript.svg"
|
||||
import { createRoot } from "react-dom/client";
|
||||
import { App } from "./app";
|
||||
|
||||
|
||||
@@ -164,7 +164,7 @@ For example:
|
||||
}
|
||||
```
|
||||
|
||||
```css abc.css
|
||||
```css abc.css icon="file-code"
|
||||
body {
|
||||
background-color: red;
|
||||
}
|
||||
@@ -174,7 +174,7 @@ body {
|
||||
|
||||
This outputs:
|
||||
|
||||
```css
|
||||
```css styles.css icon="file-code"
|
||||
body {
|
||||
background-color: red;
|
||||
}
|
||||
@@ -385,7 +385,8 @@ All paths are resolved relative to your HTML file, making it easy to organize yo
|
||||
- Need more configuration options for things like asset handling
|
||||
- Need a way to configure CORS, headers, etc.
|
||||
|
||||
If you want to submit a PR, most of the code is [here](https://github.com/oven-sh/bun/blob/main/src/bun.js/api/bun/html-rewriter.ts). You could even copy paste that file into your project and use it as a starting point.
|
||||
{/* todo: find the correct link to link to as this 404's and there isn't any similar files */}
|
||||
{/* If you want to submit a PR, most of the code is [here](https://github.com/oven-sh/bun/blob/main/src/bun.js/api/bun/html-rewriter.ts). You could even copy paste that file into your project and use it as a starting point. */}
|
||||
|
||||
</Warning>
|
||||
|
||||
|
||||
@@ -106,7 +106,7 @@ For each file specified in `entrypoints`, Bun will generate a new bundle. This b
|
||||
|
||||
The contents of `out/index.js` will look something like this:
|
||||
|
||||
```ts title="out/index.js" icon="/icons/javascript.svg"
|
||||
```js title="out/index.js" icon="/icons/javascript.svg"
|
||||
// out/index.js
|
||||
// ...
|
||||
// ~20k lines of code
|
||||
@@ -527,7 +527,7 @@ Injects environment variables into the bundled output by converting `process.env
|
||||
|
||||
For the input below:
|
||||
|
||||
```ts title="input.js" icon="/icons/javascript.svg"
|
||||
```js title="input.js" icon="/icons/javascript.svg"
|
||||
// input.js
|
||||
console.log(process.env.FOO);
|
||||
console.log(process.env.BAZ);
|
||||
@@ -535,7 +535,7 @@ console.log(process.env.BAZ);
|
||||
|
||||
The generated bundle will contain the following code:
|
||||
|
||||
```ts title="output.js" icon="/icons/javascript.svg"
|
||||
```js title="output.js" icon="/icons/javascript.svg"
|
||||
// output.js
|
||||
console.log("bar");
|
||||
console.log("123");
|
||||
@@ -580,7 +580,7 @@ console.log(process.env.BAZ);
|
||||
|
||||
The generated bundle will contain the following code:
|
||||
|
||||
```ts title="output.js" icon="/icons/javascript.svg"
|
||||
```js title="output.js" icon="/icons/javascript.svg"
|
||||
console.log(process.env.FOO);
|
||||
console.log("https://acme.com");
|
||||
console.log(process.env.BAZ);
|
||||
@@ -722,7 +722,7 @@ Normally, bundling `index.tsx` would generate a bundle containing the entire sou
|
||||
|
||||
The generated bundle will look something like this:
|
||||
|
||||
```ts title="out/index.js" icon="/icons/javascript.svg"
|
||||
```js title="out/index.js" icon="/icons/javascript.svg"
|
||||
import { z } from "zod";
|
||||
|
||||
// ...
|
||||
@@ -1026,7 +1026,7 @@ Setting `publicPath` will prefix all file paths with the specified value.
|
||||
|
||||
The output file would now look something like this.
|
||||
|
||||
```ts title="out/index.js" icon="/icons/javascript.svg"
|
||||
```js title="out/index.js" icon="/icons/javascript.svg"
|
||||
var logo = "https://cdn.example.com/logo-a7305bdef.svg";
|
||||
```
|
||||
|
||||
@@ -1356,10 +1356,12 @@ interface BuildConfig {
|
||||
* JSX configuration object for controlling JSX transform behavior
|
||||
*/
|
||||
jsx?: {
|
||||
runtime?: "automatic" | "classic";
|
||||
importSource?: string;
|
||||
factory?: string;
|
||||
fragment?: string;
|
||||
importSource?: string;
|
||||
runtime?: "automatic" | "classic";
|
||||
sideEffects?: boolean;
|
||||
development?: boolean;
|
||||
};
|
||||
naming?:
|
||||
| string
|
||||
@@ -1443,13 +1445,20 @@ interface BuildConfig {
|
||||
drop?: string[];
|
||||
|
||||
/**
|
||||
* When set to `true`, the returned promise rejects with an AggregateError when a build failure happens.
|
||||
* When set to `false`, the `success` property of the returned object will be `false` when a build failure happens.
|
||||
* - When set to `true`, the returned promise rejects with an AggregateError when a build failure happens.
|
||||
* - When set to `false`, returns a {@link BuildOutput} with `{success: false}`
|
||||
*
|
||||
* This defaults to `false` in Bun 1.1 and will change to `true` in Bun 1.2
|
||||
* as most usage of `Bun.build` forgets to check for errors.
|
||||
* @default true
|
||||
*/
|
||||
throw?: boolean;
|
||||
|
||||
/**
|
||||
* Custom tsconfig.json file path to use for path resolution.
|
||||
* Equivalent to `--tsconfig-override` in the CLI.
|
||||
*/
|
||||
tsconfig?: string;
|
||||
|
||||
outdir?: string;
|
||||
}
|
||||
|
||||
interface BuildOutput {
|
||||
|
||||
@@ -312,7 +312,7 @@ The `html` loader processes HTML files and bundles any referenced assets. It wil
|
||||
|
||||
For example, given this HTML file:
|
||||
|
||||
```html title="src/index.html"
|
||||
```html title="src/index.html" icon="file-code"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
@@ -325,7 +325,7 @@ For example, given this HTML file:
|
||||
|
||||
It will output a new HTML file with the bundled assets:
|
||||
|
||||
```html title="dist/index.html"
|
||||
```html title="dist/index.html" icon="file-code"
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<body>
|
||||
|
||||
@@ -87,7 +87,7 @@ macro();
|
||||
|
||||
When shipping a library containing a macro to npm or another package registry, use the `"macro"` export condition to provide a special version of your package exclusively for the macro environment.
|
||||
|
||||
```json title="package.json" icon="file-code"
|
||||
```json title="package.json" icon="file-json"
|
||||
{
|
||||
"name": "my-package",
|
||||
"exports": {
|
||||
|
||||
@@ -456,7 +456,6 @@
|
||||
"pages": [
|
||||
"/guides/test/run-tests",
|
||||
"/guides/test/watch-mode",
|
||||
"/guides/test/concurrent-test-glob",
|
||||
"/guides/test/migrate-from-jest",
|
||||
"/guides/test/mock-functions",
|
||||
"/guides/test/spy-on",
|
||||
@@ -465,6 +464,7 @@
|
||||
"/guides/test/update-snapshots",
|
||||
"/guides/test/coverage",
|
||||
"/guides/test/coverage-threshold",
|
||||
"/guides/test/concurrent-test-glob",
|
||||
"/guides/test/skip-tests",
|
||||
"/guides/test/todo-tests",
|
||||
"/guides/test/timeout",
|
||||
|
||||
@@ -4,13 +4,9 @@ description: Share feedback, bug reports, and feature requests
|
||||
mode: center
|
||||
---
|
||||
|
||||
import Feedback from "/snippets/cli/feedback.mdx";
|
||||
|
||||
Whether you've found a bug, have a performance issue, or just want to suggest an improvement, here's how you can open a helpful issue:
|
||||
|
||||
<Callout icon="discord">
|
||||
For general questions, please join our [Discord](https://discord.com/invite/CXdq2DP29u).
|
||||
</Callout>
|
||||
<Callout icon="discord">For general questions, please join our [Discord](https://bun.com/discord).</Callout>
|
||||
|
||||
## Reporting Issues
|
||||
|
||||
@@ -56,9 +52,7 @@ Whether you've found a bug, have a performance issue, or just want to suggest an
|
||||
<Note>
|
||||
- For MacOS and Linux: copy the output of `uname -mprs`
|
||||
- For Windows: copy the output of this command in the powershell console:
|
||||
```powershell
|
||||
"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"
|
||||
```
|
||||
`"$([Environment]::OSVersion | ForEach-Object VersionString) $(if ([Environment]::Is64BitOperatingSystem) { "x64" } else { "x86" })"`
|
||||
</Note>
|
||||
</Step>
|
||||
|
||||
@@ -79,7 +73,3 @@ echo "please document X" | bun feedback --email you@example.com
|
||||
```
|
||||
|
||||
You can provide feedback as text arguments, file paths, or piped input.
|
||||
|
||||
---
|
||||
|
||||
<Feedback />
|
||||
|
||||
@@ -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.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user