mirror of
https://github.com/oven-sh/bun
synced 2026-02-14 12:51:54 +00:00
More guides and fixing links (#3960)
* More guides * WIP * Updates * Fix
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
{% callout %}
|
||||
|
||||
<!-- **Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. Existing Node.js projects may use Bun's [nearly complete](/docs/runtime/nodejs-apis#node_fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module. -->
|
||||
<!-- **Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. Existing Node.js projects may use Bun's [nearly complete](/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module. -->
|
||||
|
||||
**Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. For operations that are not yet available with `Bun.file`, such as `mkdir`, you can use Bun's [nearly complete](/docs/runtime/nodejs-apis#node_fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module.
|
||||
**Note** — The `Bun.file` and `Bun.write` APIs documented on this page are heavily optimized and represent the recommended way to perform file-system tasks using Bun. For operations that are not yet available with `Bun.file`, such as `mkdir`, you can use Bun's [nearly complete](/docs/runtime/nodejs-apis#node-fs) implementation of the [`node:fs`](https://nodejs.org/api/fs.html) module.
|
||||
|
||||
{% /callout %}
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ Bun implements the following globals.
|
||||
|
||||
- [`Buffer`](https://nodejs.org/api/buffer.html#class-buffer)
|
||||
- Node.js
|
||||
- See [Node.js > `Buffer`](/docs/runtime/nodejs-apis#node_buffer)
|
||||
- See [Node.js > `Buffer`](/docs/runtime/nodejs-apis#node-buffer)
|
||||
|
||||
---
|
||||
|
||||
@@ -172,7 +172,7 @@ Bun implements the following globals.
|
||||
|
||||
- [`global`](https://nodejs.org/api/globals.html#global)
|
||||
- Node.js
|
||||
- See [Node.js > `global`](/docs/runtime/nodejs-apis#node_global).
|
||||
- See [Node.js > `global`](/docs/runtime/nodejs-apis#global).
|
||||
|
||||
---
|
||||
|
||||
@@ -220,7 +220,7 @@ Bun implements the following globals.
|
||||
|
||||
- [`process`](https://nodejs.org/api/process.html)
|
||||
- Node.js
|
||||
- See [Node.js > `process`](/docs/runtime/nodejs-apis#node_process)
|
||||
- See [Node.js > `process`](/docs/runtime/nodejs-apis#node-process)
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ app.listen(port, () => {
|
||||
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. These modules can also be used directly, though [`Bun.serve`](/docs/api/http) is recommended for most use cases.
|
||||
|
||||
{% callout %}
|
||||
**Note** — Refer to the [Runtime > Node.js APIs](/docs/runtime/nodejs-apis#node_http) page for more detailed compatibility information.
|
||||
**Note** — Refer to the [Runtime > Node.js APIs](/docs/runtime/nodejs-apis#node-http) page for more detailed compatibility information.
|
||||
{% /callout %}
|
||||
|
||||
```ts
|
||||
|
||||
@@ -5,7 +5,7 @@ name: Build an HTTP server using Express and Bun
|
||||
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.
|
||||
|
||||
{% callout %}
|
||||
Refer to the [Runtime > Node.js APIs](/docs/runtime/nodejs-apis#node_http) page for more detailed compatibility information.
|
||||
Refer to the [Runtime > Node.js APIs](/docs/runtime/nodejs-apis#node-http) page for more detailed compatibility information.
|
||||
{% /callout %}
|
||||
|
||||
```sh
|
||||
|
||||
31
docs/guides/ecosystem/nextjs.md
Normal file
31
docs/guides/ecosystem/nextjs.md
Normal file
@@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Build an app with Next.js and Bun
|
||||
---
|
||||
|
||||
{% callout %}
|
||||
Next.js currently relies on Node.js APIs that Bun does not yet implement. The guide below uses Bun to initialize a project and install dependencies, but it uses Node.js to run the dev server.
|
||||
{% /callout %}
|
||||
|
||||
---
|
||||
|
||||
Initialize a Next.js app with `create-next-app`. This automatically installs dependencies using `npm`.
|
||||
|
||||
```sh
|
||||
$ bunx create-next-app
|
||||
✔ What is your project named? … my-app
|
||||
✔ Would you like to use TypeScript with this project? … No / Yes
|
||||
✔ Would you like to use ESLint with this project? … No / Yes
|
||||
✔ Would you like to use `src/` directory with this project? … No / Yes
|
||||
✔ Would you like to use experimental `app/` directory with this project? … No / Yes
|
||||
✔ What import alias would you like configured? … @/*
|
||||
Creating a new Next.js app in /path/to/my-app.
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
To start the dev server, run `bun run dev` from the project root.
|
||||
|
||||
```sh
|
||||
$ cd my-app
|
||||
$ bun run dev
|
||||
```
|
||||
42
docs/guides/install/yarnlock.md
Normal file
42
docs/guides/install/yarnlock.md
Normal file
@@ -0,0 +1,42 @@
|
||||
---
|
||||
name: Generate a human-readable lockfile
|
||||
---
|
||||
|
||||
By default Bun generates a binary `bun.lockb` file when you run `bun install`. In some cases, it's preferable to generate a human-readable lockfile instead.
|
||||
|
||||
---
|
||||
|
||||
Use the `--yarn` flag to generate a Yarn-compatible `yarn.lock` file (in addition to `bun.lockb`).
|
||||
|
||||
```sh
|
||||
$ bun install --yarn
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
To set this as the default behavior, add the following to your `bunfig.toml` file.
|
||||
|
||||
```toml#bunfig.toml
|
||||
[install]
|
||||
print = "yarn"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
To print a Yarn lockfile to your console without writing it to disk, just "run" your `bun.lockb` with `bun`.
|
||||
|
||||
```sh
|
||||
$ bun bun.lockb
|
||||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||
# yarn lockfile v1
|
||||
# bun ./bun.lockb --hash: 9BFBF11D86084AAB-9418b03ff880c569-390CE6459EACEC9A...
|
||||
|
||||
abab@^2.0.6:
|
||||
version "2.0.6"
|
||||
resolved "https://registry.npmjs.org/abab/-/abab-2.0.6.tgz"
|
||||
integrity sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvH...
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
See [Docs > Package manager](/docs/cli/install) for complete documentation of Bun's package manager.
|
||||
@@ -28,4 +28,4 @@ if (errors) {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation..
|
||||
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation.
|
||||
|
||||
@@ -23,4 +23,4 @@ const proc = Bun.spawn(["echo", "hello"], {
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation..
|
||||
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation.
|
||||
|
||||
@@ -38,4 +38,4 @@ output; // => "hello"
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation..
|
||||
See [Docs > API > Child processes](/docs/api/spawn) for complete documentation.
|
||||
|
||||
@@ -13,10 +13,10 @@ const stream = await file.stream();
|
||||
|
||||
---
|
||||
|
||||
The chunks of the stream can be consumed with `for await`.
|
||||
The chunks of the stream can be consumed as an [async iterable](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_async_iterator_and_async_iterable_protocols) using `for await`.
|
||||
|
||||
```ts
|
||||
for await (const chunk of stream.values()) {
|
||||
for await (const chunk of stream) {
|
||||
chunk; // => Uint8Array
|
||||
}
|
||||
```
|
||||
|
||||
@@ -12,4 +12,4 @@ const decoded = atob(encoded); // => "hello world"
|
||||
|
||||
---
|
||||
|
||||
See [Docs > API > Hashing](/docs/api/hashing#bun-password) for complete documentation.
|
||||
See [Docs > Web APIs](/docs/runtime/web-apis) for a complete breakdown of the Web APIs implemented in Bun.
|
||||
|
||||
@@ -17,7 +17,7 @@ The following Web APIs are partially or completely supported.
|
||||
---
|
||||
|
||||
- Web Workers
|
||||
- [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) [`self.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/postMessage) [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone). Missing `MessagePort`, `MessageChannel`, `BroadcastChannel`.
|
||||
- [`Worker`](https://developer.mozilla.org/en-US/docs/Web/API/Worker) [`self.postMessage`](https://developer.mozilla.org/en-US/docs/Web/API/DedicatedWorkerGlobalScope/postMessage) [`structuredClone`](https://developer.mozilla.org/en-US/docs/Web/API/structuredClone) [`MessagePort`](https://developer.mozilla.org/en-US/docs/Web/API/MessagePort) [`MessageChannel`](https://developer.mozilla.org/en-US/docs/Web/API/MessageChannel). Missing `BroadcastChannel`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user