{"id":15147524,"url":"https://github.com/hhpr98/bun-learning","last_synced_at":"2026-01-21T16:02:44.737Z","repository":{"id":204128322,"uuid":"710350132","full_name":"hhpr98/bun-learning","owner":"hhpr98","description":"Learning progress for bunJS","archived":false,"fork":false,"pushed_at":"2024-11-20T16:50:20.000Z","size":82,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-07T01:14:23.414Z","etag":null,"topics":["api","bun","bunjs","learning","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hhpr98.png","metadata":{"files":{"readme":"README.dev.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-26T14:17:03.000Z","updated_at":"2024-11-20T16:50:24.000Z","dependencies_parsed_at":"2024-04-08T17:43:53.892Z","dependency_job_id":"bb7e1bf7-aa82-43f7-9b09-a54c4b6881f3","html_url":"https://github.com/hhpr98/bun-learning","commit_stats":{"total_commits":23,"total_committers":1,"mean_commits":23.0,"dds":0.0,"last_synced_commit":"74dd97347027cfd661e0bf8f1452e9c75ce68ce6"},"previous_names":["hhpr98/bun-learning"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hhpr98/bun-learning","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpr98%2Fbun-learning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpr98%2Fbun-learning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpr98%2Fbun-learning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpr98%2Fbun-learning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hhpr98","download_url":"https://codeload.github.com/hhpr98/bun-learning/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hhpr98%2Fbun-learning/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28635926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-21T15:01:31.228Z","status":"ssl_error","status_checked_at":"2026-01-21T14:42:58.942Z","response_time":86,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","bun","bunjs","learning","typescript"],"created_at":"2024-09-26T12:41:58.302Z","updated_at":"2026-01-21T16:02:44.715Z","avatar_url":"https://github.com/hhpr98.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Executing program test bun\n\n## Bun test seq, yes, basename, dirname\n```sh\nbun foo\\hello.js\n```\n\n## Bun start both script without open 2 (or more) terminals and cd into them\n```sh\n# bun run --filter \u003cworkspace\u003e \u003cscript\u003e\n# OR bun --filter='*' dev\n# OR bun --filter 'packages/api' --filter 'packages/frontend' dev\ncd bun_workspaces\nbun run --filter \"*\" dev # will run both dev script of ws1 and ws2\n```\n\n## Bun open file with no 2nd parameter (callback)\n```sh\nbun bun_fs\\bun_fs_close\\index.ts\n```\n\n## Bun writeFile example\n```sh\nbun bun_fs\\bun_fs_write_file\\index.ts\n```\n\n## Bun fs appendFile example\n```sh\nbun bun_fs\\bun_fs_append_file\\index.ts\n```\n\n## Bun using database, sqlite file control, db_throw_on_err example\n```sh\nbun bun_database\\bun_db_using.ts\nbun bun_database\\bun_db_file_control.ts\nbun bun_database\\bun_db_close_on_throw_error.ts\nbun bun_database\\bun_db_join.ts\n```\n\n## Bun which() with case-insensitive\n```sh\nbun foo\\bun_which.ts\n```\n\n## Bun cwd flag (change working directory)\n```sh\nbun --cwd=.\\foo run bun_test.ts\n```\n\n## Bun abort signal (for referal only)\n```ts\nconst first = new AbortController().signal;\nconst second = new AbortController().signal;\nfetch(\"https://example.com\", {\n  signal: first,\n});\nfetch(\"https://example.com\", {\n  signal: second,\n});\n\nconst abortSignal = AbortSignal.any([first, second]);\n\n// Cancel this when either `first` or `second` is aborted\nawait fetch(\"https://example.com/slow\", { signal: abortSignal });\n```\n\n## To cross-compile a TypeScript or JavaScript application to a different platform, use the `--target` option with `bun build --compile`:\n\n```sh\n# Linux x64\nbun build --compile --target=bun-linux-x64 server.ts\n\n# Windows x64\nbun build --compile --target=bun-windows-x64 server.ts\n\n# macOS Silicon\nbun build --compile --target=bun-darwin-arm64 server.ts\n\n# Linux arm64\nbun build --compile --target=bun-linux-arm64 server.ts\n```\n\n## Bun now allow to comment in package.json (but we do not recommend it)\n```json\n{\n  \"name\": \"bun-learning\",\n  // Now allow comment in bun.js\n  \"module\": \"index.ts\",\n  \"type\": \"module\",\n  \"devDependencies\": {\n    \"bun-types\": \"latest\"\n  },\n  \"peerDependencies\": {\n    \"typescript\": \"^5.0.0\"\n  },\n  \"dependencies\": {\n    \"express\": \"^4.18.3\"\n  }\n}\n```\n\n## Bun run with `--hot` or `--watch` command to automatically reload bun (if have TC39 stage3 proposal Import Attributes)\n\n```ts\nimport html from \"./index.html\" with type { type: \"text\" };\nconsole.log(html);\n\nimport json from \"./config.foo\" with { type: \"json\" };\nconsole.log(json); // { \"name\": \"app\" } (converted to JSON object)\n\nimport cfg from \"./Configfile\" with { type: \"toml\" };\nconsole.log(cfg); // { \"name\": \"app\" }\n```\n\n## Bun.serve() now supports Server Name Indication (SNI)\n\nYou can now specify multiple `serverName` TLS entries in `Bun.serve`. This is useful when you want to serve multiple TLS certificates or hostnames on the same port.\n\n```ts\nimport { serve } from \"bun\";\n\nserve({\n  port: 443,\n  tls: [\n    {\n      cert: Bun.file(\"./example.pem\"),\n      key: Bun.file(\"./example-key.pem\"),\n      serverName: \"*.example.com\",\n    },\n    {\n      cert: Bun.file(\"./test.pem\"),\n      key: Bun.file(\"./test-key.pem\"),\n      serverName: \"*.test.com\",\n    },\n  ],\n  fetch(request) {\n    return new Response(\"Using TLS!\");\n  },\n});\n```\n\n## Bun.Glob (scan file)\n\n```sh\nbun run bun_glob\\index.ts\n```\n\n## Bun compile (compile to a `bun_test.exe` file)\n```sh\nbun build --compile .\\foo\\bun_test.ts --outfile .\\foo\\build\\bun_test\n```\n\n## Dlopen (open lib) with bun (supported `.so`, `.dylib`, `.dll` file)\n```ts\nimport { dlopen } from \"bun:ffi\";\n\nconst lib = dlopen(import.meta.resolve(\"./lib.so\") /* ... symbols */);\n```\n\n## Bun build with `--define` param\n```sh\nbun --cwd=.\\bun_define build .\\index.ts --target=bun --outfile=build.js # none crash\nbun --cwd=.\\bun_define build .\\index.ts --target=bun --outfile=build.js --define \"console.log=console.error\"\n```\n\n## Bun test with existsSync\n```sh\nbun --cwd=.\\bun_fs\\bun_fs_exist_sync run .\\index.ts # Expected is `false false false true`\n```\n\n## Bun with `npm-run-all` to run parrallel scripts\n```json\n{\n  \"name\": \"bun-learning\",\n  \"module\": \"index.ts\",\n  \"type\": \"module\",\n  \"devDependencies\": {\n    \"bun-types\": \"latest\"\n  },\n  \"peerDependencies\": {\n    \"typescript\": \"^5.0.0\"\n  },\n  \"dependencies\": {\n    \"express\": \"^4.18.3\",\n    \"npm-run-all\": \"^4.1.5\"\n  },\n  \"scripts\": {\n    \"all\": \"npm-run-all --parallel start dev\",\n    \"start\": \"bun run server.ts\",\n    \"dev\": \"bun --cwd=foo run bun_test.ts\"\n  }\n}\n```\n\nJust run `bun run all` to execute both `start` and `dev`\n\n## Bun test with crypto\n```sh\nbun --cwd=bun_crypto index.ts # 3338be694f50c5f338814986cdf0686453a888b84f424d792af4b9202398f392\n```\n\n## Bunx cowsay\n```sh\nbunx cowsay \"Hello, world!\"\n```\n\n## Bun UDP socket\n```sh\nbun bun_udp_socket\\index.js\n```\nThe output is:\n```\nmessage from 127.0.0.1:54324:\nHello!\n```\n\n## Bun node:dgram\n```sh\nbun node_dgram\\send-10-messages.js\n```\n\n## Bun request override\n```sh\nbun foo\\bun_request.js\n```\n\nThe output is:\n```\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\u003cmeta charset=\"utf-8\"\u003e\n\u003ctitle\u003eError\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cpre\u003eCannot POST /\u003c/pre\u003e  \u003c===== See the method here\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Bun node:dns\n```sh\nbun node_dns\\index.js # hiii\n```\n\n## Bun json import\n```\nbun bun_json_import\\index.js\n```\n\nThe ouput is:\n```json\n{\n  test: 0,\n}\n```\n\n## Bun test\nRun the followings to test all test cases:\n```sh\nbun test\n```\n\n## Bunx version\n```sh\nbunx --version # 1.1.34\n```\n\n## Bun web socket\n\nStart a ws server:\n```sh\nbun web_socket\\ws_server.js\n```\n\nStart ws client\n```sh\nbun web_socket\\ws_client.js\n```\n\n## Bun throw version at the end\n```sh\nbun bun_error\\bun_error_throw_version.js #Bun v1.1.34 (Windows x64)\n```\n\n## Bun shell with empty command\n\nWill throw error without hang\n```sh\nbun bun_shell\\bun_shell_empty.js\n```\n\n### Bun build\n\nBuild command\n```sh\nbun build --complile .\\bun_build\\express.js --sourcemap=external --outdir .\n```\n\nIntegration test\n```sh\nbun build --complile .\\bun_build\\express.js --minify \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhpr98%2Fbun-learning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhhpr98%2Fbun-learning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhhpr98%2Fbun-learning/lists"}