5.00
(1 Rating)

Bun Course – Introduction to bun & Elysia

Categories: bun
Wishlist Share
Share Course
Page Link
Share On Social Media

About Course

Have you ever wondered how bun JS works? Wonder no more because I break it all down in this introductory bun course for you!

If you’re looking for the best training course on creating servers in bun then you’ve found it!

Online bun Course

  • Basic bun JS concepts
  • Programming in Javascript and Typescript
  • bun equivalents to nodeJS
  • And much more (expand section details below to discover everything)!

Why is bun Fast?

Bun.js is a modern JavaScript runtime designed to be fast, efficient, and developer-friendly. It is written in Zig, a low-level programming language known for performance and safety. There are several reasons why Bun.js is considered fast:

Zig

Bun.js is written in Zig which is a low-level language known for its manual memory management, small binary size, and no garbage collection. Zig allows Bun.js to have finer control over performance optimizations, memory usage, and system-level operations compared to JavaScript runtimes written in languages like C++ (e.g., Node.js’s V8 engine).

Optimized JavaScriptCore (JSC) Engine

Bun uses JavaScriptCore (JSC), the JavaScript engine that powers WebKit (the engine behind Safari). JSC is a highly optimized engine with a just-in-time (JIT) compiler, which translates JavaScript code into machine code at runtime. Bun takes advantage of JSC’s optimizations, like speculative optimizations and inlining, to execute JavaScript code faster than other engines like V8 (used by Node.js).

Highly Efficient Bundling, Transpiling, and Minification

Bun comes with a fast, built-in JavaScript and TypeScript bundler, transpiler, and minifier, all written from scratch in Zig. Traditional tools like Babel and Webpack are often slower because they are written in JavaScript or require multiple processing stages. Bun’s bundling and transpiling pipeline is designed to be fast, handling dependencies, transformations, and optimizations in a streamlined way.

Native TypeScript and JSX Support

Bun has built-in support for TypeScript and JSX, meaning it can directly handle TypeScript and JSX files without needing additional plugins or loaders. This reduces overhead, speeds up the development process, and makes the runtime more efficient.

Low-Level APIs and Efficient I/O

– Bun provides low-level APIs that are built around highly efficient system calls, reducing overhead and improving performance. Bun’s APIs for file system operations, networking, and other I/O tasks are designed to be fast by minimizing context switching and unnecessary layers of abstraction.

Fast Package Manager (`bun install`)

– Bun comes with its own package manager (`bun install`) that is significantly faster than traditional package managers like npm and yarn. It speeds up package installation by optimizing network requests and leveraging parallel processing, making it one of the fastest JavaScript package managers available.

Memory Efficiency and Reduced Garbage Collection

Bun minimizes memory usage through careful management of memory allocations, reducing the frequency of garbage collection. By having better control over memory allocation and deallocation, Bun avoids performance bottlenecks associated with frequent garbage collection cycles.

Pre-compiled Native Modules

Unlike Node.js, which requires native modules to be compiled during installation, Bun uses pre-compiled native modules. This reduces the setup time and improves runtime performance since there’s no need to compile modules at runtime.

Multi-Threading Support

Bun supports multi-threading out of the box, allowing it to efficiently utilize multiple CPU cores for parallel tasks. This is particularly useful for tasks like handling network requests, file system operations, or CPU-bound tasks.

Single Executable

Bun is a single binary executable, which reduces the complexity of managing multiple dependencies and layers. This makes it lightweight and highly portable, with minimal startup time and reduced latency.

 

Show More

What Will You Learn?

  • Understand the basics of bun JS
  • Create a Raw bun Server
  • Use the Elysia framework in bun
  • Create a Server in Elysia
  • Understand URL params and body data
  • Apply schema and data validation
  • Learn architecture
  • Understand how to seperate concerns
  • Create middleware by hooking into lifecycle events (Elysia)

Course Content

Introduction to bun JS
Get an overview of bun JS and what makes it great. We cover installation, basic setup, package installation and running npm scripts.

  • Introduction to bun JS
    04:38
  • Installation and Setup
    01:51
  • Create bun Hello World
    01:47
  • Simple bun Server & Speed Comparison vs Node JS
    04:26
  • Running Scripts and Watching for Changes
    04:27
  • Install Packages at Light Speed
    04:37

Create a Native bun Server & Explore the API
In this module we will cover environment variables, hot reloading, files, JSON, GET and POST routes. I'll also go over a few gotchas!

Simple Server With the Elysia Framework
In this section we will cover: Creating basic scaffolding for an Elysia app Understanding routing in Elysia with architecture hints to separate out your concerns Extracting url parameters How to handle body data Returning valid responses Find the finished code at https://github.com/grantmk/Bun-JS-Starter-Course-Section-3

Elysia – Serving Client Apps, Typing and Enforcing Schema
- Serve static sites from our bun instance - Pointers about serving single page applications - Define schema for incoming data from URL parameters and body - Enforce schema and cast types safely on incoming data

Elysia Lifecycle & Middleware Equivalents
We will cover: Go over basic lifecycle hooks for common use cases Create our own middleware for authentication from x-access headers Use our dummy HTML page to send authenticated requests to our server Finished code at: https://github.com/grantmk/Bun-JS-Starter-Course-Section-5

How to Request More Content
Thank you for watching. I may not have covered something important so if you need anything then please watch the video to see how to request it (no promises - but I'll try!)

Student Ratings & Reviews

5.0
Total 1 Rating
5
1 Rating
4
0 Rating
3
0 Rating
2
0 Rating
1
0 Rating
A
6 months ago
Really enjoyable pace if you can already code basic JS / TS. Covers pretty much everything I needed to know to convert my existing servers into the more efficient bun versions.