How To Install BunJS On Windows

You, bunjavascriptcompilerwsl
Back

We first need to install WSL ( Windows Subsystem for Linux ) but before installing WSL, we need to make sure that our operating system has virtualization enabled. You can enable the virtualization by following the steps here

Installing WSL

After you enabled the virtualization, to install the WSL, open the terminal and enter following command

wsl --install

This command is going to install ubuntu by default, when the command is finished successfully, we can type "ubuntu" on startup and open it. We will see the command propt asking for a UNIX username, this will be our username that we will use for accessing the linux subsystem. You can also type "ubuntu" to command prompt to log in to the subsystem. We are going to need to install this extension for our IDE to properly work with WSL files. After you installed the extension, you can type code . to command prompt so you can open the wsl directory with your IDE.

Installing Bun

We need to install zip before installing bun.

sudo apt install zip

Now that we have our Linux Subsystem all setup, we can finally install bun. Type below command to subsystem prompt

curl -fsSL https://bun.sh/install | bash

Add bun to source with the command you get after curl

source /home/[your-username]/.bashrc

Now that we have bun, let's create our first bun server and give it a try

Create a file named "http.js" and put this piece of code inside the file:

export default {
  port: 3001,
  fetch(request) {
    return new Response("Welcome to Bun!");
  },
};

Please use a different port if you are already running something else on 3001.

After you saved the file you can run it with this command

bun run http.js

After you run the command, open localhost:3000, you will see the bun serving the page.

welcome-to-bun

If you want to share my content, please use the buttons below. Thank you! © Ali Gümüş TosunRSS