How To Run NestJS with Bun [Simplest Guide]

You can run NestJS with Bun

How To Run NestJS with Bun [Simplest Guide]

Bun released its version 1.0!

If you go to the release notes, the most exciting part of Bun is...

It is ( almost )  completely compatible with ( almost ) all the existing Node.js ecosystem.

Actually, they made it so compatible, some compatibility issues in Node.js doesn't even exist for Bun.

The most notable is module system, import and require keywords can exist in harmony without ever writing type: module to your package.json!

Edit: 12 September 2023

discord talk with jmcdo29 about bun support of nestjs

Well guys, that happened. Appearantly, I was tricked by the Bun commercial. Because, they advertised that Bun works with NestJS.

As I am excited about the Bun release, I jumped to the conclusions too quick. Appearantly, if you use bun start it doesn't actually use Bun under the hood. Thankfully @jmcdo29 mentioned this issue in the Discord group of NestJS.

If anyone can't load the image, here is the explanation:

By the way, bun start on a nest new project calls nest start which uses the nest CLI which has a node shebang, so it's using node, not bun.
- jmcdo29

The explanation below is not applicable currently.

How to Run NestJS with Bun

Okay, but how do you run NestJS with Bun?

Well, it is a problem of the past.

Simply:

bun start

If this doesn't work, install Bun first:

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

Don't you trust curl commands?  Then you can use npm to install Bun:

npm install -g bun

NestJS or any other web framework popular enough is guaranteed to work with Bun.