This code starts an HTTP server listening on port 3000. It responds to every request with a 200 status and the body "Welcome to Bun!".See Bun.serve for details.
server.ts
const server = Bun.serve({ port: 3000, fetch(request) { return new Response("Welcome to Bun!"); },});console.log(`Listening on ${server.url}`);
{"docsConfig":{"theme":"aspen","$schema":"https://mintlify.com/docs.json","name":"Bun","colors":{"primary":"#ff73a8","light":"#ff73a8","dark":"#ff73a8"},"logo":{"light":"https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/logo/logo-with-wordmark-dark.svg?fit=max\u0026auto=format\u0026n=82N53aP7NFbaCVSl\u0026q=85\u0026s=305b3d4bbd610e8552768a02b718eb16","dark":"https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/logo/logo-with-wordmark-light.svg?fit=max\u0026auto=format\u0026n=82N53aP7NFbaCVSl\u0026q=85\u0026s=919c779c33ae5bb39335fe92cc06509f"},"favicon":"https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/logo/bun.png?fit=max\u0026auto=format\u0026n=82N53aP7NFbaCVSl\u0026q=85\u0026s=1cdd1bd0b4d7ba6af2967ef3139d6ecc","appearance":{"default":"system"},"background":{"decoration":"gradient"},"navbar":{"links":[{"icon":"download","href":"/installation","label":"安装 Bun"}]},"footer":{"socials":{"x":"https://x.com/bunjavascript","github":"https://github.com/oven-sh/bun","discord":"https://bun.com/discord","youtube":"https://www.youtube.com/@bunjs"}},"seo":{"metatags":{"canonical":"https://bun.com/docs"}},"fonts":{"heading":{"family":"Inter Display Bold","source":"https://mintlify-assets.b-cdn.net/fonts/InterDisplay-Bold.woff2","format":"woff2"}},"icons":{"library":"lucide"},"styling":{"codeblocks":{"theme":{"light":"github-light","dark":"dracula"}},"latex":false},"contextual":{"options":["copy","view","claude","mcp","vscode"],"display":"header"},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"span-inc","hasAudioNarration":false,"actualSubdomain":"span-inc","customDomains":["bun.ll1025.cn"],"gitSource":{"type":"github","owner":"dacong-wu","repo":"docs","deployBranch":"main","contentDirectory":"","isPrivate":true,"mountPath":"","label":""},"chroma":{"latestBuiltDeploymentHistoryId":"6a5efd6981af850fd0dabfcd","collectionId":"22712792-471e-4a2d-9224-1e790a6480c3","liveDeploymentHistoryId":"6a5efd6981af850fd0dabfcd","schemaVersion":"v3"},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6a5efd6981af850fd0dabfcd:success","clientVersion":"0.0.3908","searchFilterCounts":[{"language":"default","tag":"指南","count":191},{"language":"default","tag":"运行时","count":73},{"language":"default","tag":"包管理器","count":42},{"language":"default","tag":"测试运行器","count":31},{"language":"default","tag":"实用工具","count":29},{"language":"default","tag":"生态系统与框架","count":28},{"language":"default","tag":"二进制数据","count":22},{"language":"default","tag":"文件系统","count":21},{"language":"default","tag":"进程与系统","count":18},{"language":"default","tag":"打包器","count":13}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-v7-file-tree","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"pause-universal-search-reconcile","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"per-site-search-delta","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-branches-v2-autocommit","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-branches-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-private-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"teamspace","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"vite-origin","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-nav-generations","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"byok-sep-25","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-agent-model-picker","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"client-snapshot-docs-config","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"isAtlas":false,"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":".steps{margin-top:0}div[data-component-part=card-icon]>svg{mask-size:80%}.font-mono{font-weight:700!important}.nav-tabs .nav-tabs-item{font-size:.8rem!important}.mdx-content>span[data-as=p]{margin-bottom:2rem!important}.dark\\:bg-white\\/5:is(.dark *){background-color:rgb(155 155 155/5%)}ul#sidebar-group>li>a{font-size:.825rem;line-height:1rem;font-weight:500}pre.shiki{line-height:1.4rem;font-size:.8rem}.dark\\:ring-white\\/\\[0\\.14\\]:is(.dark *){border:1px solid rgb(255 255 255/.14)!important;--tw-ring-color:transparent}.ring-transparent{border:1px solid transparent!important}.code-block:has([data-component-part=code-block-header]) div[data-component-part=code-block-root],.code-group:has([data-component-part=code-group-tab-bar]) div[data-component-part=code-block-root]{border-top-right-radius:0!important;border-top-left-radius:0!important}div[data-component-part=card-icon] img,img.code-block-icon{background:0 0!important}html.dark .card-group .card:not(:hover){border:1px solid rgb(255 255 255/.1)!important}html:not(.dark) .card-group .card{border:1px solid rgb(var(--gray-200))!important}.dark div[data-component-part=card-content-container]{background:rgb(255 255 255/.03)}.card:hover{border-color:rgb(var(--gray-400)/var(--tw-border-opacity))!important}html.dark .shiki,html.dark .shiki span{background-color:transparent!important}.prose :where(hr):not(:where([class~=\"not-prose\"], [class~=\"not-prose\"] *)){margin-top:2rem!important;margin-bottom:2rem!important}.code-block+.code-block[language=text] div.absolute.top-3,footer#footer a[href*=\"mintlify.com\"]{display:none}.nav-tabs{width:100%!important}a[href=\"/docs/guides\"],a[href=\"/guides\"]{margin-left:auto!important}div[data-component-part=card-content-container]{height:100%!important}div#guides-list div[data-component-part=card-content-container]>:nth-child(2){height:100%;display:flex;flex-direction:column;justify-content:space-between!important}.code-block+.code-block[language=text]{margin-top:-32px;z-index:-1;border-top-right-radius:0;border-top-left-radius:0;border-top:none}.code-block+.code-block[language=text],.code-block+.code-block[language=text] div[data-component-part=code-block-root]{background-color:rgb(var(--gray-50))!important}html.dark .code-block+.code-block[language=text],html.dark .code-block+.code-block[language=text] div[data-component-part=code-block-root]{background-color:#16171e!important}.code-block:has(+.code-block[language=text]),.code-block:has(+.code-block[language=text]) div[data-component-part=code-block-root]{border-bottom-right-radius:0;border-bottom-left-radius:0}div.callout .code-block{margin-bottom:0}[language=shellscript] code span.line:not(:empty):has(span)::before{content:\"$ \";color:#6272a4;user-select:none}[language=powershell] code span.line:has(>span:first-child[style*=\"#6272A4\"])::before,[language=powershell] code span.line:has(>span:first-child[style*=\"color: rgb(98, 114, 164)\"])::before,[language=shellscript] code span.line:has(>span:first-child[style*=\"#6272A4\"])::before,[language=shellscript] code span.line:has(>span:first-child[style*=\"color: rgb(98, 114, 164)\"])::before{content:\"\"}[language=powershell] code span.line:not(:empty):has(span)::before{content:\"> \";color:#6272a4;user-select:none}.dark [data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight,.dark [data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:after,.dark [data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{background:rgb(219 219 219/20%)!important}.dark[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{border-color:#fff}[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight,[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:after,[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{background:rgb(var(--gray-200)/.5)!important}[data-component-part=code-block-root]:not(.has-line-numbers) .line-highlight:before{border-color:#acacac}"}],"page":{"pagePath":"guides/http/simple","slug":"/guides/http/simple","pageMetadata":{"title":"Write a simple HTTP server","sidebarTitle":"Simple HTTP Server with Bun","mode":"center","description":null,"href":"/guides/http/simple"},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,p:`p`,pre:`pre`,span:`span`,..._provideComponents(),...props.components},{CodeBlock}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);return _jsxs(_Fragment,{children:[_jsxs(_components.p,{children:[`This code starts an HTTP server listening on port `,_jsx(_components.code,{children:`3000`}),`. It responds to every request with a `,_jsx(_components.code,{children:`200`}),` status and the body `,_jsx(_components.code,{children:`\"Welcome to Bun!\"`}),`.`]}),`\n`,_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/runtime/http/server`,children:_jsx(_components.code,{children:`Bun.serve`})}),` for details.`]}),`\n`,_jsx(CodeBlock,{filename:`server.ts`,icon:`https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max\u0026auto=format\u0026n=82N53aP7NFbaCVSl\u0026q=85\u0026s=787d39d6a7d96d7f9540dc74344eba23`,numberOfLines:`8`,language:`typescript`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light dracula`,style:{backgroundColor:`#fff`,\"--shiki-dark-bg\":`#282A36`,color:`#24292e`,\"--shiki-dark\":`#F8F8F2`},language:`typescript`,children:_jsxs(_components.code,{language:`typescript`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:`const`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#F8F8F2`},children:` server`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` =`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` Bun.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`serve`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`({`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` port`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#FF79C6`},children:`:`}),_jsx(_components.span,{style:{color:`#005CC5`,\"--shiki-dark\":`#BD93F9`},children:` 3000`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:` fetch`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#E36209`,\"--shiki-light-font-style\":`inherit`,\"--shiki-dark\":`#FFB86C`,\"--shiki-dark-font-style\":`italic`},children:`request`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`) {`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-dark\":`#FF79C6`},children:` return`}),_jsx(_components.span,{style:{color:`#D73A49`,\"--shiki-light-font-weight\":`inherit`,\"--shiki-dark\":`#FF79C6`,\"--shiki-dark-font-weight\":`bold`},children:` new`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:` Response`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:`Welcome to Bun!`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#E9F284`},children:`\"`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`);`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:` },`})}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`});`})}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`console.`}),_jsx(_components.span,{style:{color:`#6F42C1`,\"--shiki-dark\":`#50FA7B`},children:`log`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`(`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:\"`Listening on \"}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#FF79C6`},children:\"${\"}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`server`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F8F8F2`},children:`.`}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`url`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#FF79C6`},children:`}`}),_jsx(_components.span,{style:{color:`#032F62`,\"--shiki-dark\":`#F1FA8C`},children:\"`\"}),_jsx(_components.span,{style:{color:`#24292E`,\"--shiki-dark\":`#F8F8F2`},children:`);`})]}),`\n`]})})})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"codeStyling":{"theme":{"light":"github-light","dark":"dracula"}},"config":{},"pageMetadata":{"title":"Write a simple HTTP server","sidebarTitle":"Simple HTTP Server with Bun","mode":"center","description":null,"href":"/guides/http/simple"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[],"codeExamples":{}},"jsLinks":["/_mintlify/custom/span-inc/71a8c2a91b354e86/normalize-internal-links.js"],"subdomain":"span-inc","siteName":"Bun","title":"Write a simple HTTP server - Bun","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-07-21T05:03:26.808Z","originalFileLocation":"guides/http/simple.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"application-name\" content=\"Bun\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Write a simple HTTP server - Bun\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"Bun\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://bun.com/docs/guides/http/simple\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Write a simple HTTP server - Bun\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/span-inc/H6Li-Q7sSmPrB7uV/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"Bun\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#ff73a8\">\u003clink data-mint-head rel=\"canonical\" href=\"https://bun.com/docs/guides/http/simple\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/guides/http/simple.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://bun.com/#organization\",\"name\":\"Bun\",\"url\":\"https://bun.com\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/logo/logo-with-wordmark-dark.svg?fit=max\u0026auto=format\u0026n=82N53aP7NFbaCVSl\u0026q=85\u0026s=305b3d4bbd610e8552768a02b718eb16\"}},{\"@type\":\"WebSite\",\"@id\":\"https://bun.com/docs#website\",\"name\":\"Bun\",\"url\":\"https://bun.com/docs\",\"publisher\":{\"@id\":\"https://bun.com/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://bun.com/docs/guides/http/simple#webpage\",\"url\":\"https://bun.com/docs/guides/http/simple\",\"name\":\"Write a simple HTTP server\",\"dateModified\":\"2026-07-21T05:03:26.808Z\",\"isPartOf\":{\"@id\":\"https://bun.com/docs#website\"},\"breadcrumb\":{\"@id\":\"https://bun.com/docs/guides/http/simple#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://bun.com/docs/guides/http/simple#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"HTTP 与网络\",\"item\":\"https://bun.com/docs/guides/http/server\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Write a simple HTTP server\",\"item\":\"https://bun.com/docs/guides/http/simple\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://bun.com/docs/guides/http/simple#article\",\"headline\":\"Write a simple HTTP server\",\"name\":\"Write a simple HTTP server\",\"url\":\"https://bun.com/docs/guides/http/simple\",\"mainEntityOfPage\":{\"@id\":\"https://bun.com/docs/guides/http/simple#webpage\"},\"dateModified\":\"2026-07-21T05:03:26.808Z\",\"publisher\":{\"@id\":\"https://bun.com/#organization\"},\"isPartOf\":{\"@id\":\"https://bun.com/docs#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"Bun\",\"creator\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","siteName":"Bun","nav":{"global":null,"tabs":[{"tab":"运行时","icon":"cog","pages":[{"title":"运行时","href":""}]},{"tab":"包管理器","icon":"box","pages":[{"title":"包管理器","href":"/pm/cli/install"}]},{"tab":"打包器","icon":"combine","pages":[{"title":"打包器","href":"/bundler"}]},{"tab":"测试运行器","icon":"flask-conical","pages":[{"title":"测试运行器","href":"/test"}]},{"tab":"指南","icon":"map","groups":[{"group":"概览","icon":"globe","pages":[{"title":"指南","mode":"center","href":"/guides"}]},{"group":"部署","icon":"rocket","pages":[{"title":"在 Vercel 上部署 Bun 应用","sidebarTitle":"部署到 Vercel","mode":"center","href":"/guides/deployment/vercel"},{"title":"在 Railway 上部署 Bun 应用","sidebarTitle":"部署到 Railway","mode":"center","href":"/guides/deployment/railway"},{"title":"在 Render 上部署 Bun 应用","sidebarTitle":"部署到 Render","mode":"center","href":"/guides/deployment/render"},{"title":"在 AWS Lambda 上部署 Bun 应用","sidebarTitle":"部署到 AWS Lambda","mode":"center","href":"/guides/deployment/aws-lambda"},{"title":"在 DigitalOcean 上部署 Bun 应用","sidebarTitle":"部署到 DigitalOcean","mode":"center","href":"/guides/deployment/digital-ocean"},{"title":"在 Google Cloud Run 上部署 Bun 应用","sidebarTitle":"部署到 Google Cloud Run","mode":"center","href":"/guides/deployment/google-cloud-run"}]},{"group":"运行时与调试","icon":"bug","pages":[{"title":"为 Bun 安装 TypeScript 声明","sidebarTitle":"TypeScript 类型","mode":"center","href":"/guides/runtime/typescript"},{"title":"重映射导入路径","sidebarTitle":"重映射导入路径","mode":"center","href":"/guides/runtime/tsconfig-paths"},{"title":"使用 VS Code 扩展调试 Bun","sidebarTitle":"VS Code 调试器","mode":"center","href":"/guides/runtime/vscode-debugger"},{"title":"使用 Web 调试器调试 Bun","sidebarTitle":"Web 调试器","mode":"center","href":"/guides/runtime/web-debugger"},{"title":"使用 V8 堆快照检查内存使用情况","sidebarTitle":"堆快照","mode":"center","href":"/guides/runtime/heap-snapshot"},{"title":"使用 --define 的构建时常量","sidebarTitle":"构建时常量","mode":"center","href":"/guides/runtime/build-time-constants"},{"title":"定义和替换静态全局变量与常量","sidebarTitle":"定义常量","mode":"center","href":"/guides/runtime/define-constant"},{"title":"在 GitHub Actions 中安装和运行 Bun","sidebarTitle":"GitHub Actions","mode":"center","href":"/guides/runtime/cicd"},{"title":"对 macOS 单文件 JavaScript 可执行文件进行代码签名","sidebarTitle":"macOS 代码签名","mode":"center","href":"/guides/runtime/codesign-macos-executable"}]},{"group":"实用工具","icon":"wrench","pages":[{"title":"将 Bun 升级到最新版本","sidebarTitle":"升级 Bun","mode":"center","href":"/guides/util/upgrade"},{"title":"检测代码是否在 Bun 中执行","sidebarTitle":"检测 Bun","mode":"center","href":"/guides/util/detect-bun"},{"title":"获取当前 Bun 版本","sidebarTitle":"获取 Bun 版本","mode":"center","href":"/guides/util/version"},{"title":"哈希密码","sidebarTitle":"哈希密码","mode":"center","href":"/guides/util/hash-a-password"},{"title":"生成 UUID","sidebarTitle":"生成 UUID","mode":"center","href":"/guides/util/javascript-uuid"},{"title":"编码和解码 base64 数据","sidebarTitle":"Base64 编码","mode":"center","href":"/guides/util/base64"},{"title":"使用 gzip 压缩和解压数据","sidebarTitle":"Gzip 压缩","mode":"center","href":"/guides/util/gzip"},{"title":"使用 DEFLATE 压缩和解压数据","sidebarTitle":"DEFLATE 压缩","mode":"center","href":"/guides/util/deflate"},{"title":"转义 HTML 字符串","sidebarTitle":"转义 HTML","mode":"center","href":"/guides/util/escape-html"},{"title":"检查两个对象是否深度相等","sidebarTitle":"深度相等","mode":"center","href":"/guides/util/deep-equals"},{"title":"休眠固定毫秒数","sidebarTitle":"休眠","mode":"center","href":"/guides/util/sleep"},{"title":"将文件 URL 转换为绝对路径","sidebarTitle":"文件 URL 转路径","mode":"center","href":"/guides/util/file-url-to-path"},{"title":"将绝对路径转换为文件 URL","sidebarTitle":"路径转文件 URL","mode":"center","href":"/guides/util/path-to-file-url"},{"title":"获取可执行文件的路径","sidebarTitle":"查找可执行文件路径","mode":"center","href":"/guides/util/which-path-to-executable-bin"},{"title":"获取当前文件所在目录","sidebarTitle":"import.meta.dir","mode":"center","href":"/guides/util/import-meta-dir"},{"title":"获取当前文件的文件名","sidebarTitle":"import.meta.file","mode":"center","href":"/guides/util/import-meta-file"},{"title":"获取当前文件的绝对路径","sidebarTitle":"import.meta.path","mode":"center","href":"/guides/util/import-meta-path"},{"title":"检查当前文件是否为入口点","sidebarTitle":"检查入口点","mode":"center","href":"/guides/util/entrypoint"},{"title":"获取当前入口点的绝对路径","sidebarTitle":"获取入口点路径","mode":"center","href":"/guides/util/main"}]},{"group":"生态系统与框架","icon":"puzzle","pages":[{"title":"使用 Astro 和 Bun 构建应用","sidebarTitle":"Astro 与 Bun","mode":"center","href":"/guides/ecosystem/astro"},{"title":"创建 Discord 机器人","sidebarTitle":"Discord.js 与 Bun","mode":"center","href":"/guides/ecosystem/discordjs"},{"title":"使用 Docker 容器化 Bun 应用","sidebarTitle":"Docker 与 Bun","mode":"center","href":"/guides/ecosystem/docker"},{"title":"使用 Drizzle ORM 与 Bun","sidebarTitle":"Drizzle 与 Bun","mode":"center","href":"/guides/ecosystem/drizzle"},{"title":"使用 Gel 与 Bun","sidebarTitle":"Gel 与 Bun","mode":"center","href":"/guides/ecosystem/gel"},{"title":"使用 Elysia 和 Bun 构建 HTTP 服务器","sidebarTitle":"Elysia 与 Bun","mode":"center","href":"/guides/ecosystem/elysia"},{"title":"使用 Express 和 Bun 构建 HTTP 服务器","sidebarTitle":"Express 与 Bun","mode":"center","href":"/guides/ecosystem/express"},{"title":"使用 Hono 和 Bun 构建 HTTP 服务器","sidebarTitle":"Hono 与 Bun","mode":"center","href":"/guides/ecosystem/hono"},{"title":"使用 Mongoose 和 Bun 读写 MongoDB 数据","sidebarTitle":"Mongoose 与 Bun","mode":"center","href":"/guides/ecosystem/mongoose"},{"title":"通过 Drizzle ORM 使用 Neon Postgres","sidebarTitle":"Neon Drizzle 与 Bun","mode":"center","href":"/guides/ecosystem/neon-drizzle"},{"title":"使用 Neon 的无服务器 Postgres 与 Bun","sidebarTitle":"Neon 无服务器 Postgres 与 Bun","mode":"center","href":"/guides/ecosystem/neon-serverless-postgres"},{"title":"使用 Next.js 和 Bun 构建应用","sidebarTitle":"Next.js 与 Bun","mode":"center","href":"/guides/ecosystem/nextjs"},{"title":"使用 Nuxt 和 Bun 构建应用","sidebarTitle":"Nuxt 与 Bun","mode":"center","href":"/guides/ecosystem/nuxt"},{"title":"使用 PM2 将 Bun 作为守护进程运行","sidebarTitle":"PM2 与 Bun","mode":"center","href":"/guides/ecosystem/pm2"},{"title":"使用 Prisma 与 Bun","sidebarTitle":"Prisma ORM 与 Bun","mode":"center","href":"/guides/ecosystem/prisma"},{"title":"使用 Prisma Postgres 与 Bun","sidebarTitle":"Prisma Postgres 与 Bun","mode":"center","href":"/guides/ecosystem/prisma-postgres"},{"title":"使用 Qwik 和 Bun 构建应用","sidebarTitle":"Qwik 与 Bun","mode":"center","href":"/guides/ecosystem/qwik"},{"title":"使用 Bun 构建 React 应用","sidebarTitle":"React 与 Bun","mode":"center","href":"/guides/ecosystem/react"},{"title":"使用 Remix 和 Bun 构建应用","sidebarTitle":"Remix 与 Bun","mode":"center","href":"/guides/ecosystem/remix"},{"title":"使用 TanStack Start 与 Bun","sidebarTitle":"TanStack Start 与 Bun","mode":"center","href":"/guides/ecosystem/tanstack-start"},{"title":"将 Sentry 添加到 Bun 应用","sidebarTitle":"Sentry 与 Bun","mode":"center","href":"/guides/ecosystem/sentry"},{"title":"使用 SolidStart 和 Bun 构建应用","sidebarTitle":"SolidStart 与 Bun","mode":"center","href":"/guides/ecosystem/solidstart"},{"title":"服务端渲染(SSR)React 组件","sidebarTitle":"SSR React 与 Bun","mode":"center","href":"/guides/ecosystem/ssr-react"},{"title":"使用 StricJS 和 Bun 构建 HTTP 服务器","sidebarTitle":"StricJS 与 Bun","mode":"center","href":"/guides/ecosystem/stric"},{"title":"使用 SvelteKit 和 Bun 构建应用","sidebarTitle":"SvelteKit 与 Bun","mode":"center","href":"/guides/ecosystem/sveltekit"},{"title":"使用 systemd 将 Bun 作为守护进程运行","sidebarTitle":"systemd 与 Bun","mode":"center","href":"/guides/ecosystem/systemd"},{"title":"使用 Vite 和 Bun 构建前端","sidebarTitle":"Vite 与 Bun","mode":"center","href":"/guides/ecosystem/vite"},{"title":"Bun Redis 与 Upstash","sidebarTitle":"Upstash 与 Bun","mode":"center","href":"/guides/ecosystem/upstash"}]},{"group":"HTTP 与网络","icon":"globe","pages":[{"title":"Common HTTP server usage","sidebarTitle":"HTTP Server with Bun","mode":"center","description":null,"href":"/guides/http/server"},{"title":"Write a simple HTTP server","sidebarTitle":"Simple HTTP Server with Bun","mode":"center","href":"/guides/http/simple"},{"title":"Send an HTTP request using fetch","sidebarTitle":"Fetch with Bun","mode":"center","description":null,"href":"/guides/http/fetch"},{"title":"Hot reload an HTTP server","sidebarTitle":"Hot reload an HTTP server","mode":"center","href":"/guides/http/hot"},{"title":"Start a cluster of HTTP servers","sidebarTitle":"Start a cluster of HTTP servers","mode":"center","href":"/guides/http/cluster"},{"title":"Configure TLS on an HTTP server","sidebarTitle":"Configure TLS","mode":"center","href":"/guides/http/tls"},{"title":"Proxy HTTP requests using fetch()","sidebarTitle":"Proxy HTTP requests using fetch()","mode":"center","href":"/guides/http/proxy"},{"title":"Stream a file as an HTTP Response","sidebarTitle":"Stream file response","mode":"center","href":"/guides/http/stream-file"},{"title":"Upload files via HTTP using FormData","sidebarTitle":"Upload files via HTTP using FormData","mode":"center","href":"/guides/http/file-uploads"},{"title":"fetch with unix domain sockets in Bun","sidebarTitle":"Fetch with unix domain sockets","mode":"center","href":"/guides/http/fetch-unix"},{"title":"Streaming HTTP Server with Async Iterators","sidebarTitle":"Stream with iterators","mode":"center","href":"/guides/http/stream-iterator"},{"title":"Server-Sent Events (SSE) with Bun","sidebarTitle":"Server-Sent Events","mode":"center","href":"/guides/http/sse"},{"title":"Streaming HTTP Server with Node.js Streams","sidebarTitle":"Stream with Node.js","mode":"center","href":"/guides/http/stream-node-streams-in-bun"}]},{"group":"WebSocket","icon":"radio","pages":[{"title":"构建简单的 WebSocket 服务器","sidebarTitle":"简单服务器","mode":"center","href":"/guides/websocket/simple"},{"title":"构建发布-订阅 WebSocket 服务器","sidebarTitle":"发布-订阅服务器","mode":"center","href":"/guides/websocket/pubsub"},{"title":"在 WebSocket 上设置每个套接字的上下文数据","sidebarTitle":"上下文数据","mode":"center","href":"/guides/websocket/context"},{"title":"为 WebSocket 消息启用压缩","sidebarTitle":"启用压缩","mode":"center","href":"/guides/websocket/compression"}]},{"group":"进程与系统","icon":"cpu","pages":[{"title":"衍生子进程","sidebarTitle":"衍生子进程","mode":"center","href":"/guides/process/spawn"},{"title":"读取子进程的标准输出","sidebarTitle":"读取标准输出","mode":"center","href":"/guides/process/spawn-stdout"},{"title":"读取子进程的标准错误输出","sidebarTitle":"读取标准错误输出","mode":"center","href":"/guides/process/spawn-stderr"},{"title":"解析命令行参数","sidebarTitle":"解析命令行参数","mode":"center","href":"/guides/process/argv"},{"title":"从标准输入读取","sidebarTitle":"从标准输入读取","mode":"center","href":"/guides/process/stdin"},{"title":"衍生子进程并通过 IPC 通信","sidebarTitle":"衍生子进程并通过 IPC 通信","mode":"center","href":"/guides/process/ipc"},{"title":"监听 CTRL+C","sidebarTitle":"监听 CTRL+C","mode":"center","href":"/guides/process/ctrl-c"},{"title":"监听操作系统信号","sidebarTitle":"操作系统信号","mode":"center","href":"/guides/process/os-signals"},{"title":"获取进程运行时间的纳秒数","sidebarTitle":"进程运行时间","mode":"center","href":"/guides/process/nanoseconds"},{"title":"运行 Shell 命令","sidebarTitle":"运行 Shell 命令","mode":"center","href":"/guides/runtime/shell"},{"title":"在 Bun 中设置时区","sidebarTitle":"设置时区","mode":"center","href":"/guides/runtime/timezone"},{"title":"设置环境变量","sidebarTitle":"设置环境变量","mode":"center","href":"/guides/runtime/set-env"},{"title":"读取环境变量","sidebarTitle":"读取环境变量","mode":"center","href":"/guides/runtime/read-env"}]},{"group":"包管理器","icon":"package","pages":[{"title":"Add a dependency","sidebarTitle":"Add a dependency","mode":"center","href":"/guides/install/add"},{"title":"Add a development dependency","sidebarTitle":"Add a dev dependency","mode":"center","href":"/guides/install/add-dev"},{"title":"Add an optional dependency","sidebarTitle":"Add an optional dependency","mode":"center","href":"/guides/install/add-optional"},{"title":"Add a peer dependency","sidebarTitle":"Add a peer dependency","mode":"center","href":"/guides/install/add-peer"},{"title":"Add a Git dependency","sidebarTitle":"Add a Git dependency","mode":"center","href":"/guides/install/add-git"},{"title":"Add a tarball dependency","sidebarTitle":"Add a tarball dependency","mode":"center","href":"/guides/install/add-tarball"},{"title":"Install a package under a different name","sidebarTitle":"Install with alias","mode":"center","href":"/guides/install/npm-alias"},{"title":"Configuring a monorepo using workspaces","sidebarTitle":"Workspaces with Bun","mode":"center","href":"/guides/install/workspaces"},{"title":"Override the default npm registry for bun install","sidebarTitle":"Override the default npm registry","mode":"center","href":"/guides/install/custom-registry"},{"title":"Configure a private registry for an organization scope with bun install","sidebarTitle":"Configure a scoped registry","mode":"center","href":"/guides/install/registry-scope"},{"title":"Using bun install with an Azure Artifacts npm registry","sidebarTitle":"Azure Artifacts with Bun","mode":"center","href":"/guides/install/azure-artifacts"},{"title":"Using bun install with Artifactory","sidebarTitle":"JFrog Artifactory with Bun","mode":"center","href":"/guides/install/jfrog-artifactory"},{"title":"Add a trusted dependency","sidebarTitle":"Add a trusted dependency","mode":"center","href":"/guides/install/trusted"},{"title":"Generate a yarn-compatible lockfile","sidebarTitle":"Generate a yarn-compatible lockfile","mode":"center","href":"/guides/install/yarnlock"},{"title":"Migrate from npm install to bun install","sidebarTitle":"Migrate from npm to bun","mode":"center","href":"/guides/install/from-npm-install-to-bun-install"},{"title":"Configure git to diff Bun's lockb lockfile","sidebarTitle":"Configure git to diff Bun's lockfile","mode":"center","href":"/guides/install/git-diff-bun-lockfile"},{"title":"Install dependencies with Bun in GitHub Actions","sidebarTitle":"Install Bun in GitHub Actions","mode":"center","href":"/guides/install/cicd"}]},{"group":"测试运行器","icon":"flask-conical","pages":[{"title":"使用 Bun 测试运行器运行测试","sidebarTitle":"运行测试","mode":"center","href":"/guides/test/run-tests"},{"title":"使用 Bun 在监听模式下运行测试","sidebarTitle":"监听模式","mode":"center","href":"/guides/test/watch-mode"},{"title":"从 Jest 迁移到 Bun 的测试运行器","sidebarTitle":"从 Jest 迁移","mode":"center","href":"/guides/test/migrate-from-jest"},{"title":"在 `bun test` 中模拟函数","sidebarTitle":"模拟函数","mode":"center","href":"/guides/test/mock-functions"},{"title":"在 `bun test` 中监视方法","sidebarTitle":"监视方法","mode":"center","href":"/guides/test/spy-on"},{"title":"在 Bun 的测试运行器中设置系统时间","sidebarTitle":"模拟系统时间","mode":"center","href":"/guides/test/mock-clock"},{"title":"在 `bun test` 中使用快照测试","sidebarTitle":"快照测试","mode":"center","href":"/guides/test/snapshot"},{"title":"在 `bun test` 中更新快照","sidebarTitle":"更新快照","mode":"center","href":"/guides/test/update-snapshots"},{"title":"使用 Bun 测试运行器生成代码覆盖率报告","sidebarTitle":"覆盖率报告","mode":"center","href":"/guides/test/coverage"},{"title":"使用 Bun 测试运行器设置代码覆盖率阈值","sidebarTitle":"覆盖率阈值","mode":"center","href":"/guides/test/coverage-threshold"},{"title":"使用 glob 模式选择性地并发运行测试","sidebarTitle":"并发测试 glob","mode":"center","href":"/guides/test/concurrent-test-glob"},{"title":"使用 Bun 测试运行器跳过测试","sidebarTitle":"跳过测试","mode":"center","href":"/guides/test/skip-tests"},{"title":"使用 Bun 测试运行器将测试标记为\"待办\"","sidebarTitle":"待办测试","mode":"center","href":"/guides/test/todo-tests"},{"title":"使用 Bun 测试运行器设置每个测试的超时时间","sidebarTitle":"测试超时","mode":"center","href":"/guides/test/timeout"},{"title":"使用 Bun 测试运行器及早退出","sidebarTitle":"及早退出","mode":"center","href":"/guides/test/bail"},{"title":"使用 Bun 测试运行器多次重新运行测试","sidebarTitle":"重新运行测试","mode":"center","href":"/guides/test/rerun-each"},{"title":"在 Bun 中使用 Testing Library","sidebarTitle":"Testing Library","mode":"center","href":"/guides/test/testing-library"},{"title":"使用 Bun 和 happy-dom 编写浏览器 DOM 测试","sidebarTitle":"DOM 测试","mode":"center","href":"/guides/test/happy-dom"},{"title":"使用 bun test 导入、require 和测试 Svelte 组件","sidebarTitle":"测试 Svelte","mode":"center","href":"/guides/test/svelte-test"}]},{"group":"运行时与调试","icon":"bug","pages":[{"title":"使用 VS Code 扩展调试 Bun","sidebarTitle":"VS Code 调试器","mode":"center","href":"/guides/runtime/vscode-debugger"},{"title":"使用 Web 调试器调试 Bun","sidebarTitle":"Web 调试器","mode":"center","href":"/guides/runtime/web-debugger"},{"title":"使用 V8 堆快照检查内存使用情况","sidebarTitle":"堆快照","mode":"center","href":"/guides/runtime/heap-snapshot"},{"title":"使用 --define 的构建时常量","sidebarTitle":"构建时常量","mode":"center","href":"/guides/runtime/build-time-constants"},{"title":"定义和替换静态全局变量与常量","sidebarTitle":"定义常量","mode":"center","href":"/guides/runtime/define-constant"},{"title":"在 GitHub Actions 中安装和运行 Bun","sidebarTitle":"GitHub Actions","mode":"center","href":"/guides/runtime/cicd"},{"title":"对 macOS 单文件 JavaScript 可执行文件进行代码签名","sidebarTitle":"macOS 代码签名","mode":"center","href":"/guides/runtime/codesign-macos-executable"}]},{"group":"模块系统","icon":"box","pages":[{"title":"导入 JSON 文件","sidebarTitle":"导入 JSON","mode":"center","href":"/guides/runtime/import-json"},{"title":"导入 TOML 文件","sidebarTitle":"导入 TOML","mode":"center","href":"/guides/runtime/import-toml"},{"title":"导入 YAML 文件","sidebarTitle":"导入 YAML","mode":"center","href":"/guides/runtime/import-yaml"},{"title":"导入 JSON5 文件","sidebarTitle":"导入 JSON5","mode":"center","href":"/guides/runtime/import-json5"},{"title":"将 HTML 文件作为文本导入","sidebarTitle":"导入 HTML","mode":"center","href":"/guides/runtime/import-html"},{"title":"获取当前文件所在目录","sidebarTitle":"import.meta.dir","mode":"center","href":"/guides/util/import-meta-dir"},{"title":"获取当前文件的文件名","sidebarTitle":"import.meta.file","mode":"center","href":"/guides/util/import-meta-file"},{"title":"获取当前文件的绝对路径","sidebarTitle":"import.meta.path","mode":"center","href":"/guides/util/import-meta-path"},{"title":"检查当前文件是否为入口点","sidebarTitle":"检查入口点","mode":"center","href":"/guides/util/entrypoint"},{"title":"获取当前入口点的绝对路径","sidebarTitle":"获取入口点路径","mode":"center","href":"/guides/util/main"}]},{"group":"文件系统","icon":"folder","pages":[{"title":"读取文件为字符串","sidebarTitle":"读取为字符串","mode":"center","href":"/guides/read-file/string"},{"title":"读取文件为 Buffer","sidebarTitle":"读取为 Buffer","mode":"center","href":"/guides/read-file/buffer"},{"title":"读取文件为 Uint8Array","sidebarTitle":"读取为 Uint8Array","mode":"center","href":"/guides/read-file/uint8array"},{"title":"读取文件为 ArrayBuffer","sidebarTitle":"读取为 ArrayBuffer","mode":"center","href":"/guides/read-file/arraybuffer"},{"title":"读取 JSON 文件","sidebarTitle":"读取 JSON 文件","mode":"center","href":"/guides/read-file/json"},{"title":"获取文件的 MIME 类型","sidebarTitle":"获取 MIME 类型","mode":"center","href":"/guides/read-file/mime"},{"title":"检查文件是否存在","sidebarTitle":"检查文件是否存在","mode":"center","href":"/guides/read-file/exists"},{"title":"监听目录变化","sidebarTitle":"监听目录","mode":"center","href":"/guides/read-file/watch"},{"title":"以 ReadableStream 形式读取文件","sidebarTitle":"以流形式读取","mode":"center","href":"/guides/read-file/stream"},{"title":"将字符串写入文件","sidebarTitle":"将字符串写入文件","mode":"center","href":"/guides/write-file/basic"},{"title":"将 Blob 写入文件","sidebarTitle":"写入 Blob","mode":"center","href":"/guides/write-file/blob"},{"title":"将 Response 写入文件","sidebarTitle":"写入 Response","mode":"center","href":"/guides/write-file/response"},{"title":"向文件追加内容","sidebarTitle":"追加到文件","mode":"center","href":"/guides/write-file/append"},{"title":"增量写入文件","sidebarTitle":"增量写入","mode":"center","href":"/guides/write-file/filesink"},{"title":"将 ReadableStream 写入文件","sidebarTitle":"写入流","mode":"center","href":"/guides/write-file/stream"},{"title":"写入标准输出","sidebarTitle":"写入标准输出","mode":"center","href":"/guides/write-file/stdout"},{"title":"将文件写入标准输出","sidebarTitle":"将文件写入标准输出","mode":"center","href":"/guides/write-file/cat"},{"title":"将文件复制到另一个位置","sidebarTitle":"复制文件","mode":"center","href":"/guides/write-file/file-cp"},{"title":"删除文件","sidebarTitle":"删除文件","mode":"center","href":"/guides/write-file/unlink"},{"title":"删除文件","sidebarTitle":"删除文件","mode":"center","href":"/guides/runtime/delete-file"},{"title":"删除目录","sidebarTitle":"删除目录","mode":"center","href":"/guides/runtime/delete-directory"}]},{"group":"实用工具","icon":"wrench","pages":[{"title":"哈希密码","sidebarTitle":"哈希密码","mode":"center","href":"/guides/util/hash-a-password"},{"title":"生成 UUID","sidebarTitle":"生成 UUID","mode":"center","href":"/guides/util/javascript-uuid"},{"title":"编码和解码 base64 数据","sidebarTitle":"Base64 编码","mode":"center","href":"/guides/util/base64"},{"title":"使用 gzip 压缩和解压数据","sidebarTitle":"Gzip 压缩","mode":"center","href":"/guides/util/gzip"},{"title":"使用 DEFLATE 压缩和解压数据","sidebarTitle":"DEFLATE 压缩","mode":"center","href":"/guides/util/deflate"},{"title":"转义 HTML 字符串","sidebarTitle":"转义 HTML","mode":"center","href":"/guides/util/escape-html"},{"title":"检查两个对象是否深度相等","sidebarTitle":"深度相等","mode":"center","href":"/guides/util/deep-equals"},{"title":"休眠固定毫秒数","sidebarTitle":"休眠","mode":"center","href":"/guides/util/sleep"},{"title":"将文件 URL 转换为绝对路径","sidebarTitle":"文件 URL 转路径","mode":"center","href":"/guides/util/file-url-to-path"},{"title":"将绝对路径转换为文件 URL","sidebarTitle":"路径转文件 URL","mode":"center","href":"/guides/util/path-to-file-url"},{"title":"获取可执行文件的路径","sidebarTitle":"查找可执行文件路径","mode":"center","href":"/guides/util/which-path-to-executable-bin"}]},{"group":"HTML 处理","icon":"file-code","pages":[{"title":"Extract links from a webpage using HTMLRewriter","sidebarTitle":"Extract links using HTMLRewriter","mode":"center","href":"/guides/html-rewriter/extract-links"},{"title":"Extract social share images and Open Graph tags","sidebarTitle":"OpenGraph tags","mode":"center","href":"/guides/html-rewriter/extract-social-meta"}]},{"group":"二进制数据","icon":"binary","pages":[{"title":"将 ArrayBuffer 转换为字符串","sidebarTitle":"ArrayBuffer 转换为 string","mode":"center","href":"/guides/binary/arraybuffer-to-string"},{"title":"将 ArrayBuffer 转换为 Buffer","sidebarTitle":"ArrayBuffer 转换为 Buffer","mode":"center","href":"/guides/binary/arraybuffer-to-buffer"},{"title":"将 ArrayBuffer 转换为 Blob","sidebarTitle":"ArrayBuffer 转换为 Blob","mode":"center","href":"/guides/binary/arraybuffer-to-blob"},{"title":"将 ArrayBuffer 转换为数字数组","sidebarTitle":"ArrayBuffer 转换为 Array","mode":"center","href":"/guides/binary/arraybuffer-to-array"},{"title":"将 ArrayBuffer 转换为 Uint8Array","sidebarTitle":"ArrayBuffer 转换为 Uint8Array","mode":"center","href":"/guides/binary/arraybuffer-to-typedarray"},{"title":"将 Buffer 转换为字符串","sidebarTitle":"Buffer 转换为 string","mode":"center","href":"/guides/binary/buffer-to-string"},{"title":"将 Buffer 转换为 ArrayBuffer","sidebarTitle":"Buffer 转换为 ArrayBuffer","mode":"center","href":"/guides/binary/buffer-to-arraybuffer"},{"title":"将 Buffer 转换为 Blob","sidebarTitle":"Buffer 转换为 Blob","mode":"center","href":"/guides/binary/buffer-to-blob"},{"title":"将 Buffer 转换为 Uint8Array","sidebarTitle":"Buffer 转换为 Uint8Array","mode":"center","href":"/guides/binary/buffer-to-typedarray"},{"title":"将 Buffer 转换为 ReadableStream","sidebarTitle":"Buffer 转换为 ReadableStream","mode":"center","href":"/guides/binary/buffer-to-readablestream"},{"title":"将 Blob 转换为字符串","sidebarTitle":"Blob 转换为 string","mode":"center","href":"/guides/binary/blob-to-string"},{"title":"将 Blob 转换为 ArrayBuffer","sidebarTitle":"Blob 转换为 ArrayBuffer","mode":"center","href":"/guides/binary/blob-to-arraybuffer"},{"title":"将 Blob 转换为 Uint8Array","sidebarTitle":"Blob 转换为 Uint8Array","mode":"center","href":"/guides/binary/blob-to-typedarray"},{"title":"将 Blob 转换为 DataView","sidebarTitle":"Blob 转换为 DataView","mode":"center","href":"/guides/binary/blob-to-dataview"},{"title":"将 Blob 转换为 ReadableStream","sidebarTitle":"Blob 转换为 ReadableStream","mode":"center","href":"/guides/binary/blob-to-stream"},{"title":"将 Uint8Array 转换为字符串","sidebarTitle":"Uint8Array 转换为 string","mode":"center","href":"/guides/binary/typedarray-to-string"},{"title":"将 Uint8Array 转换为 ArrayBuffer","sidebarTitle":"Uint8Array 转换为 ArrayBuffer","mode":"center","href":"/guides/binary/typedarray-to-arraybuffer"},{"title":"将 Uint8Array 转换为 Buffer","sidebarTitle":"Uint8Array 转换为 Buffer","mode":"center","href":"/guides/binary/typedarray-to-buffer"},{"title":"将 Uint8Array 转换为 Blob","sidebarTitle":"Uint8Array 转换为 Blob","mode":"center","href":"/guides/binary/typedarray-to-blob"},{"title":"将 Uint8Array 转换为 DataView","sidebarTitle":"Uint8Array 转换为 DataView","mode":"center","href":"/guides/binary/typedarray-to-dataview"},{"title":"将 Uint8Array 转换为 ReadableStream","sidebarTitle":"Uint8Array 转换为 ReadableStream","mode":"center","href":"/guides/binary/typedarray-to-readablestream"},{"title":"将 DataView 转换为字符串","sidebarTitle":"DataView 转换为 string","mode":"center","href":"/guides/binary/dataview-to-string"}]},{"group":"流","icon":"waves","pages":[{"title":"将 ReadableStream 转换为字符串","sidebarTitle":"流转字符串","mode":"center","href":"/guides/streams/to-string"},{"title":"将 ReadableStream 转换为 JSON","sidebarTitle":"流转 JSON","mode":"center","href":"/guides/streams/to-json"},{"title":"将 ReadableStream 转换为 Blob","sidebarTitle":"流转 Blob","mode":"center","href":"/guides/streams/to-blob"},{"title":"将 ReadableStream 转换为 Buffer","sidebarTitle":"流转 Buffer","mode":"center","href":"/guides/streams/to-buffer"},{"title":"将 ReadableStream 转换为 ArrayBuffer","sidebarTitle":"流转 ArrayBuffer","mode":"center","href":"/guides/streams/to-arraybuffer"},{"title":"将 ReadableStream 转换为 Uint8Array","sidebarTitle":"流转 Uint8Array","mode":"center","href":"/guides/streams/to-typedarray"},{"title":"将 ReadableStream 转换为数据块数组","sidebarTitle":"流转数组","mode":"center","href":"/guides/streams/to-array"},{"title":"将 Node.js Readable 转换为字符串","sidebarTitle":"Readable 转字符串","mode":"center","href":"/guides/streams/node-readable-to-string"},{"title":"将 Node.js Readable 转换为 JSON","sidebarTitle":"Readable 转 JSON","mode":"center","href":"/guides/streams/node-readable-to-json"},{"title":"将 Node.js Readable 转换为 Blob","sidebarTitle":"Readable 转 Blob","mode":"center","href":"/guides/streams/node-readable-to-blob"},{"title":"将 Node.js Readable 转换为 Uint8Array","sidebarTitle":"Readable 转 Uint8Array","mode":"center","href":"/guides/streams/node-readable-to-uint8array"},{"title":"将 Node.js Readable 转换为 ArrayBuffer","sidebarTitle":"Readable 转 ArrayBuffer","mode":"center","href":"/guides/streams/node-readable-to-arraybuffer"}]}]},{"tab":"参考文档","icon":"book","href":"https://bun.com/reference"},{"tab":"博客","icon":"newspaper","href":"https://bun.com/blog"},{"tab":"反馈","icon":"lightbulb","pages":[{"title":"反馈","href":"/feedback"}]}]},"title":"Write a simple HTTP server - Bun","buildId":"dpl_CUnGQP1HgFUzoxatVC37y4zP83Vx","deploymentId":"dpl_CUnGQP1HgFUzoxatVC37y4zP83Vx","dynamics":[],"chunks":[]}