Bun js Hot Reload – Full Guide

Bun incudes 2 very handy flags that will watch your project for file changes. I also cover this in my bun Elysia course.

1. Reload with the –watch flag

This is used in the command to run your server, eg:

bun --watch index.ts

If a files contents change within your project folder then bun will cold reload your project – equivalent to restarting the server. All states and connections will be destroyed.

2. Reload with the –hot flag

bun --hot index.ts

Again, if files change then bun will reload your project but only the code directly affected. This keeps state and connections open. Obviously if the changed code affects state or connection then you may have very strange debug issues!

Personally I like to just use –watch. I have very very few instances where it would save my time to keep state or connections. However, I could see the use for it on a production server so there was a minimum of user disruption.

If you want to know more then see my full hot reload guide here.

Alternatively you can also check out my course on bun and Elysia Framework, which has everything you need to get you started.

Leave a Comment