
Bun Has a Free API — Here's How to Use the All-in-One JavaScript Runtime
Bun is a fast all-in-one JavaScript runtime that includes a bundler, test runner, and package manager. It is 3-4x faster than Node.js for many operations. Installation curl -fsSL https://bun.sh/install | bash Running JavaScript bun run index.ts # Direct TypeScript execution bun run index.js # JavaScript bun run index.jsx # JSX support built-in HTTP Server const server = Bun . serve ({ port : 3000 , async fetch ( req ) { const url = new URL ( req . url ); if ( url . pathname === " /api/hello " ) { return Response . json ({ message : " Hello from Bun! " }); } if ( url . pathname === " /api/posts " && req . method === " POST " ) { const body = await req . json (); return Response . json ({ created : body }, { status : 201 }); } return new Response ( " Not Found " , { status : 404 }); } }); console . log ( `Server running at ${ server . url } ` ); File I/O // Read file const content = await Bun . file ( " data.json " ). text (); const data = JSON . parse ( content ); // Write file await Bu
Continue reading on Dev.to JavaScript
Opens in a new tab


