Change language

Bun: a new runtime for JavaScript

|

The public beta was released the other day. Let's see what Bun is interesting for.

What is runtime?

A runtime environment in computer science is a computing environment required for the execution of a computer program and available during the execution of a computer program. In the runtime environment, as a rule, it is impossible to change the source code of the program, but access to operating system environment variables, object tables, and shared library modules can be accessed.

Bun competes with the well-known NodeJS and Deno.

How Bun positions itself:

… Bun is a new JavaScript runtime with a native builder, transpiler, task runner and built-in npm client.

The main difference from competitors is speed. And that's why:

Bun uses the JavaScriptCore engine (which is under the hood of Safari), which is slightly faster to start and execute commands.

Bun is written in Zig, a low-level programming language that implements manual memory management.

The author of Bun regularly optimizes the code.

What Bun can do

  • transpiles JSX/TS code
  • supports working with npm
  • has built-in API for modules like fetch, WebSocket, ReadableStreams.
  • Test Runner like Jest, only faster
  • HTTP Server
  • Application assembly (bundling)

Trying it

Installation:

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

Let's write a simple http server. Create http.js file:


//http.js
export default {
port: 3000
fetch(request) {
return new Response("Welcome to Bun!");
},
};
Run: bun run http.js

We check by opening http://localhost:3000 in the browser

Summary

Since this is beta, a lot of things don't work. For example, when I tried to run mocha tests from my NodeJS project, I found out that:

  • decorators are not supported
  • built-in node:child_process module not implemented

There is a list with what does not work yet.

You can try calling bun install on your project and compare the speed of installing packages compared to npm/yarn

In general, I was waiting for the release, as I followed the author on Twitter for the last year and it was clear how he put a lot of time and effort into the project. I hope that with a full-fledged release we will release more stable functionality and it will be possible to launch it on production. Also, the author contributes to JavaScriptCore, which moves the web forward.

Michael Zippo
2022/07/10

https://linkedin.com/in/michael-zippo-9136441b1
[email protected]

Sources: Python.Engineering

Shop

Learn programming in R: courses

$

Best Python online courses for 2022

$

Best laptop for Fortnite

$

Best laptop for Excel

$

Best laptop for Solidworks

$

Best laptop for Roblox

$

Best computer for crypto mining

$

Best laptop for Sims 4

$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

News


Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method