Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I use Bun.js to run existing Express.js applications without modifications


Can I use Bun.js to run existing Express.js applications without modifications


Yes, you can use Bun.js to run existing Express.js applications without modifications. Bun is designed as a drop-in replacement for Node.js, which means that it supports the same APIs and libraries that Node.js does, including Express.

Key Points

- Compatibility: Bun implements the `node:http` and `node:https` modules that Express relies on, allowing Express applications to run out of the box with no changes needed[2][5].

- Installation: To use Express with Bun, you simply need to install Express in your Bun project using `bun add express`, and then you can define your routes and start your server as you would in a standard Node.js environment[3][6].

- Running the Server: You can start your Express server using the `bun run` command, similar to how you would with Node.js. For example:

javascript
  import express from "express";

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

  app.get("/", (req, res) => {
      res.send("Hello from Express with Bun!");
  });

  app.listen(port, () => {
      console.log(`Server is running on https://localhost:${port}`);
  });
  

You would run this file with:

bash
  bun run server.ts
  

- No Modifications Required: Since Bun aims for compatibility with existing Node.js applications, most libraries and frameworks that work in Node.js should also function correctly in Bun without any code changes[4][8].

In summary, if you have an existing Express.js application, you can run it using Bun without needing to modify your code.

Citations:
[1] https://betterprogramming.pub/write-a-express-like-api-using-bunjs-79e77a6a7a31?gi=fcaaedfca5e8
[2] https://bun.sh/guides/ecosystem/express
[3] https://dev.to/clerijr/your-first-api-with-bun-express-and-prisma-p90
[4] https://kinsta.com/blog/bun-sh/
[5] https://bun.sh/blog/bun-v1.0
[6] https://blog.bitsrc.io/building-an-api-using-express-js-mongodb-bun-cbac231d1cd3?gi=963b0726988c
[7] https://bun.sh/docs/bundler/executables
[8] https://www.builder.io/blog/bun-vs-node-js