How to use any Nodejs dependened modules (pino-pretty, pm2) with Bunjs

bunjs, pino, pino-pretty, fix, pm2

Why This Occurs?

  • pino-pretty requires Node.js to execute

  • Thus it looks for the node executable.

How to Resolve?

First, find the installation path of **`pino-pretty`** using the **`which`** command
which pino-pretty
Then, you can use **`bun`** to execute **`pino-pretty`** by specifying its full path.

- _This can indeed be cumbersome_ 😅

Suppose the path is **`$HOME/.bun/bin/pino-pretty`**
bun $HOME/.bun/bin/pino-pretty
Here’s an example of how to use **`bun`** to pipe the output of a TypeScript file through **`pino-pretty`**
bun src/index.ts | bun $(which pino-pretty)
# bun src/index.ts | bun $HOME/.bun/bin/pino-pretty

In the example provided, you're using bun to execute a TypeScript file and then piping (|) the output to pino-pretty which is also being run with bun. This is assuming that bun can work as a drop-in replacement for node in this scenario. However, be cautious with this approach as it might not be applicable for all Nodejs packages or scripts due to compatibility issues.

Last updated

© 2024 ~ Yunus Emre Ak ~ yEmreAk