DEV Community

Cover image for A crash course in using Bunjs instead of Node.js on Linux
chovy
chovy

Posted on

A crash course in using Bunjs instead of Node.js on Linux

Transitioning from Node.js to Bun on Linux: A Complete Guide

Introduction

In the evolving world of JavaScript, Bun is quickly making a name for itself as a high-performance runtime environment that's compatible with Node.js but significantly faster. This guide will walk you through the basics of getting started with Bun on a Linux system, and how it compares to the traditional Node.js setup.

Installation

Step 1: Install Bun

To install Bun on your Linux system, open your terminal and run the following command:

curl -fsSL https://bun.sh/install | bash
Enter fullscreen mode Exit fullscreen mode

This command downloads and installs Bun, automatically adding it to your path for immediate use.

Basic Commands

Here are some basic Bun commands to get you started:

  • Run a script: bun run app.js
  • Install a package: bun add express

Creating a Web Server with Express

Let's create a simple web server using Express. First, install Express using Bun:

bun add express
Enter fullscreen mode Exit fullscreen mode

Then, create a file named app.js and add the following code:

import express from 'express';

const app = express();
const port = 3000;

app.get('/', (req, res) => {
  res.send('Hello World with Bun!');
});

app.listen(port, () => {
  console.log(`Server listening at http://localhost:${port}`);
});
Enter fullscreen mode Exit fullscreen mode

Run your server with:

bun run app.js
Enter fullscreen mode Exit fullscreen mode

Differences from Node.js

Bun is designed to be faster and more efficient than Node.js:

  • Performance: Uses a high-speed JavaScript engine.
  • Built-in package manager: Simplifies your workflow by integrating package management.

Conclusion

Transitioning to Bun can significantly enhance your development workflow and application performance. Give it a try and see the difference for yourself!


Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs