npm -g bun
bun init
bun run index.ts
const server = Bun.serve({
port: 3000,
fetch(req) {
return new Response("Bun bun hello!");
},
});
console.log(`Listening on http://localhost:${server.port} ...`);
bun --watch index.ts
bun --hot index.ts
no need install dotenv packages
"scripts": {
"dev": "bun --watch index.ts",
"start": "bun run index.ts"
},
const url= new URL(req.url);
if(url.pathname === "/") return new Response("Home page");
},
import path from 'path';
const filepath = path.join("src", "modules", "index.ts");
const filename = path.basename(filepath);
console.log(filename)
const data = "lorem ipsum dolor sit amet"
await Bun.write("index.html", data)
const file = await Bun.file("index.html")
console.log(await file.text())
console.log(file.size)
console.log(await file.slice(0, 5))
console.log(await file.stream())
console.log(await file.arrayBuffer())
import {describe,expect,test,beforeAll} from "bun:test";
bun build ./src/index.ts --outfile=./dist/bundle.js
bun build ./src/index.ts --outfile=./dist/bundle.js --watch
app.tsx
bun install react react-dom