🧄 Bun meets NestJS - tweaking for development

February 4, 2024 (25d ago)

... some snippets to use Bun with NestJS, as I'm currently working on a project using both. This is not yet production ready because it is not officially supported by Nest, but it is nice to already benefit from the advantages of bun in the development phase.

Bun is not yet a supported package manager for NestJS. However, it can still be integrated into an existing project with a few tweaks. Bun can easily understand an existing package.json, so the usual npm commands work without any problems.

Advent Calendar
bun install
bun run start
bun run build

However, you should not forget that the nest cli commands are still executed with Node. To use Bun not only as a package manager, but also as a runtime, individual scripts can be adapted in the package.json. A customized package.json could then look like this:

  "scripts": {
    "build": "nest build",
    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
    "dev": "bun run src/main.ts --watch --hot",
    "start": "bun run src/main.ts",
    "start:prod": "bun run dist/main.js",
    "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
    "test": "bun test",
    "test:watch": "jest --watch",
    "test:cov": "jest --coverage",
    "test:e2e": "jest --config ./test/jest-e2e.json"
Advent Calendar

NestJS, Bun