Skip to content

an example of how to use Bun, a javascript all-in-one runtime


<- return to guides and tutorials

This content has been generated partially by Artificial Intelligence


What is Bun

Bun is a new JavaScript/TypeScript runtime built from scratch to serve the modern JavaScript ecosystem. It has three major design goals:

  • Speed. Bun starts fast and runs fast. It extends JavaScriptCore, the performance-minded JS engine built for Safari. Fast start times mean fast apps and fast APIs.
  • Elegant APIs. Bun provides a minimal set of highly-optimized APIs for performing common tasks, like starting an HTTP server and writing files.
  • Cohesive DX. Bun is a complete toolkit for building JavaScript apps, including a package manager, test runner, and bundler.

Bun is designed as a drop-in replacement for Node.js. It natively implements hundreds of Node.js and Web APIs, including fs, path, Buffer and more.

The goal of Bun is to run most of the world's server-side JavaScript and provide tools to improve performance, reduce complexity, and multiply developer productivity.

How to Bun

First, you need to have Bun installed on your computer. You can download it from the official website https://bun.sh

Once you have Bun installed, create a new directory and inside it create a new file named "app.ts". Open this file in your code editor.

In the "app.ts" file, add the following code:

// This is a simple JavaScript code to print "Hello, World!" in the console

console.log("Hello, World!");

Save the file and navigate to the directory in your terminal/command prompt.

Type in the following command to run the app:

bun run app.ts

You will see the output "Hello, World!" in your terminal.

Congratulations, you have just created your first Bun app!

Note: console.log() is a built-in function in Bun that allows you to print messages to the console.



<- return to guides and tutorials