0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Bunの使い方です。

Ubuntu 24.04 にインストール

sudo snap install bun-js

バージョンの確認

$ bun --version
1.1.12

TypeScript のプログラムを走らせる

プログラム

index.tsx
const server = Bun.serve({
  port: 3000,
  fetch(request) {
    return new Response("Bun へようこそ!");
  },
});

console.log(`Listening on localhost:${server.port}`);

Bun で実行

bun run index.tsx

クライアントで接続

http http://localhost:3000

実行結果

$ http http://localhost:3000
HTTP/1.1 200 OK
Content-Length: 20
Date: Mon, 10 Jun 2024 08:39:03 GMT
content-type: text/plain;charset=utf-8

Bun へようこそ!

JavaScript のプログラムを走らせる

プログラム

http.js
export default {
  port: 3000,
  fetch(request) {
    return new Response("皆さん こんにちは!")
  },
}

Bun で実行

bun run http.js

クライアントで接続

http http://localhost:3000

実行結果

$ http http://localhost:3000
HTTP/1.1 200 OK
Content-Length: 28
Date: Mon, 10 Jun 2024 08:41:40 GMT
content-type: text/plain;charset=utf-8

皆さん こんにちは!
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?