Portability of applications between Node, Deno & Bun
Portability of applications between Node, Deno & Bun
By Luuk Rijnbende
4 min read
Ever since the introduction of Bun there are three runtimes to choose from when wanting to develop and run a JavaScript server. Node was the one that started it all and most applications are designed to run on that, but how would those applications fare running on the other runtimes, are they really a drop-in replacement?
- Authors
- Name
- Luuk Rijnbende
- linkedinLuuk Rijnbende
- Github
- githubluukrijnbende
Now while Deno was never designed as a drop-in replacement, that is the intention of Bun. Thus both of them are tested to see how easy or difficult it is to switch to a different and potentially faster runtime. Both Deno and Bun also offer developer tools, but since this article is about the portability of existing applications, those tools are not covered.
Test setup
The test is spread over multiple applications to test common usage. While nearly not as extensive or complex as real-world applications, it should give a basic idea of how portable they are and how much effort is required to switch to a different runtime.
Because Deno requires file extensions to be present whenever importing modules, code is kept in a single file where possible for this test.
Applications
- Simple script reading some numbers from a file and adding them together with a small delay between each addition.
- Simple HTTP server using the built-in HTTP module.
- Simple HTTP server using Express.
- Nuxt 2
- Nuxt 3
- Next
- Angular Universal
Runtime versions at the time of writing
Node | 16.17.0 (LTS) |
Deno | 1.25.0 |
Bun | 0.1.10 (Beta) |
Node
Node is the JavaScript runtime that started it all back in 2009 and was built on the Google V8 JavaScript engine. Now it goes without saying that all test applications work on Node, since they were designed to. The behavior of the applications on Node will serve as a baseline for the other runtimes.
Portability
Simple script | ✅ |
Native HTTP | ✅ |
Express | ✅ |
Nuxt 2 | ✅ |
Nuxt 3 | ✅ |
Next | ✅ |
Angular Universal | ✅ |
Deno
Deno is a runtime created in 2018 aiming to solve the ‘mistakes’ made along the way with Node. Like Node, Deno makes use of the Google V8 JavaScript engine.
Deno, by default, was built to not use the NPM ecosystem and its module loading differs from that of Node. This also means that any library that accesses native Node functionality will ‘never’ work on Deno. But how does that work for any dependencies that are installed in the project? Deno downloads and includes dependencies by providing a URL as the source of an import statement, which means the code using external dependencies has to be rewritten to run on Deno.
In order to work with applications written for Node, Deno provides a compatibility mode that allows the use of Node specific APIs such as path
or fs
. This also enables using modules that were installed using NPM or Yarn instead of importing them directly from a URL.
Since the test applications were built to run on Node, they are started on Deno in Node compatibility mode by passing the flags --unstable --compat
.
Results
Script
Works without issues in compatibility mode.
Native HTTP
Works without issues in compatibility mode.
Express
Error | SyntaxError: Unexpected strict mode reserved word |
Cause | Express defines the following line exports.static = require(‘serve-static’); |
Solution | Change the line to exports.statik = require(‘serve-static’); , though this might break code using the static export. |
Link | https://github.com/denoland/deno/issues/14852 |
Nuxt 2
Error | Uncaught (in promise) TypeError: Cannot read properties of undefined (reading: ‘columns’). |
Cause | - |
Solution | - |
Link | - |
Nuxt 3
Error | [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath ‘.runtime/fetch/index’ is not defined by “exports” |
Cause | Likely the underlying Nitro engine that bundles specifically for Node |
Solution | A Deno specific preset for Nitro |
Link | https://github.com/unjs/nitro/issues/422 |
Next
Error | ReferenceError: document is not defined |
Cause | - |
Solution | - |
Link | https://github.com/vercel/next.js/discussions/26428 |
Angular Universal
Error | TypeError: Cannot read properties of undefined (reading: ‘encrypted’) as soon as a request is done |
Cause | - |
Solution | There is an experimental SSR rendered for using Angular Universal on Deno, but that involves changing the code and is also very limited in support. https://github.com/alosaur/angular_deno |
Link | https://github.com/angular/universal/issues/2338 |
Portability
Simple script | ✅ |
Native HTTP | ✅ |
Express | ❌ |
Nuxt 2 | ❌ |
Nuxt 3 | ❌ |
Next | ❌ |
Angular Universal | ❌ |
Bun
Bun is the new kid on the block, created in 2021 to be a drop-in replacement for Node. It uses the JavaScriptCore engine by Apple instead of the Google V8 JavaScript engine, which supposedly makes it faster than Node and Deno.
Bun focuses on three main things, fast startup times, new levels of performance (thanks to the JavaScriptCore engine) and being a complete tool for the developer. It natively implements most of the APIs available in Node, so changing an application from using Node to using Bun should be a piece of cake.
Results
Script
Works, but fileURLToPath
doesn’t work the same as it does on Node and Deno. process.cwd()
is used to go around this and just read from the source file. Also when reading from a file, the encoding is required for Bun to read correctly.
Native HTTP
Works, but Content-Type
response header is required, otherwise, the response will be downloaded.
Express
Works, but there is an open issue on Express support, so more advanced use cases might not work yet. https://github.com/oven-sh/bun/issues/496
Nuxt 2
Works, but still uses Node under the hood because of the usage of the Nuxt CLI. In environments without Node, such as a purpose-built Docker container, the Nuxt CLI cannot start because it’s missing Node.
Nuxt 3
Error | Could not resolve: “node-fetch-native/polyfill” |
Cause | Likely the underlying Nitro engine that bundles specifically for Node |
Solution | A Bun specific preset for Nitro |
Link | https://github.com/oven-sh/bun/issues/159 |
Next
Works, but just like Nuxt 2, still uses Node under the hood because of the usage of the Next CLI. In environments without Node, such as a purpose-built Docker container, the Next CLI cannot start because it’s missing Node.
Through the use of https://www.npmjs.com/package/bun-framework-next Next can be started in development mode with just Bun, though trying to run that in production mode will still use Node.
Angular Universal
Error | Expected scope (src.js_ast.Scope.Kind.function_args, 556073), found scope (src.js_ast.Scope.Kind.block, 556020) |
Cause | - |
Solution | - |
Link | - |
Portability
Simple script | ✅ |
Native HTTP | ✅ |
Express | ✅ |
Nuxt 2 | ❌ |
Nuxt 3 | ❌ |
Next | ✅ |
Angular Universal | ❌ |
Conclusion
The idea of running any application that was designed for Node on another runtime such as Deno or Bun is amazing as it might bring performance or workflow improvements. Sadly it is not as simple as switching out Node for Deno or Bun. Only simple applications and scripts will work on all three runtimes, but more advanced use cases designed for Node still only run on Node.
Deno was created as an alternative for Node but not a replacement, so it isn’t strange to see that only the really simple applications work. Even with the recently introduced compatibility mode more advanced use cases don’t work and likely never will unless explicitly implemented by Deno. Applications wanting to use Deno as runtime instead of Node would have to be adapted specifically for Deno and then there might still be a framework or library that is not compatible.
Bun on the other hand was created as a replacement for Node and shows promising results when running the test applications. Because of little differences between the JavaScriptCore and V8 engine, there might be some code changes required to make it work, but nothing compared to the changes necessary for Deno. Also, there’s still the case of applications starting, but using Node under the hood because of the usage of a CLI. There are efforts to make this work, such as the Next compatibility layer, but it’s going to take some time for that to be production ready.
For now, Bun is definitely a runtime to keep an eye on, as it might really become a production-ready replacement for Node. Hopefully, it will spark an effort to improve performance as much as possible in Node as well, so that even applications that don’t work on Bun in the future can still benefit from a performance increase.
Upcoming events
The Test Automation Meetup
PLEASE RSVP SO THAT WE KNOW HOW MUCH FOOD WE WILL NEED Test automation is a cornerstone of effective software development. It's about creating robust, predictable test suites that enhance quality and reliability. By diving into automation, you're architecting systems that ensure consistency and catch issues early. This expertise not only improves the development process but also broadens your skillset, making you a more versatile team member. Whether you're a developer looking to enhance your testing skills or a QA professional aiming to dive deeper into automation, RSVP for an evening of learning, delicious food, and the fusion of coding and quality assurance! 🚀🚀 18:00 – 🚪 Doors open to the public 18:15 – 🍕 Let’s eat 19:00 – 📢 First round of Talks 19:45 – 🍹 Small break 20:00 – 📢 Second round of Talks 20:45 – 🍻 Drinks 21:00 – 🙋♀️ See you next time? First Round of Talks: The Power of Cross-browser Component Testing - Clarke Verdel, SR. Front-end Developer at iO How can you use Component Testing to ensure consistency cross-browser? Second Round of Talks: Omg who wrote this **** code!? - Erwin Heitzman, SR. Test Automation Engineer at Rabobank How can tests help you and your team? Beyond the Unit Test - Christian Würthner, SR. Android Developer at iO How can you do advanced automated testing for, for instance, biometrics? RSVP now to secure your spot, and let's explore the fascinating world of test automation together!
| Coven of Wisdom - Amsterdam
Go to page for The Test Automation MeetupCoven of Wisdom - Herentals - Winter `24 edition
Worstelen jij en je team met automated testing en performance? Kom naar onze meetup waar ervaren sprekers hun inzichten en ervaringen delen over het bouwen van robuuste en efficiënte applicaties. Schrijf je in voor een avond vol kennis, heerlijk eten en een mix van creativiteit en technologie! 🚀 18:00 – 🚪 Deuren open 18:15 – 🍕 Food & drinks 19:00 – 📢 Talk 1 20:00 – 🍹 Kleine pauze 20:15 – 📢 Talk 2 21:00 – 🙋♀️ Drinks 22:00 – 🍻 Tot de volgende keer? Tijdens deze meetup gaan we dieper in op automated testing en performance. Onze sprekers delen heel wat praktische inzichten en ervaringen. Ze vertellen je hoe je effectieve geautomatiseerde tests kunt schrijven en onderhouden, en hoe je de prestaties van je applicatie kunt optimaliseren. Houd onze updates in de gaten voor meer informatie over de sprekers en hun specifieke onderwerpen. Over iO Wij zijn iO: een groeiend team van experts die end-to-end-diensten aanbieden voor communicatie en digitale transformatie. We denken groot en werken lokaal. Aan strategie, creatie, content, marketing en technologie. In nauwe samenwerking met onze klanten om hun merken te versterken, hun digitale systemen te verbeteren en hun toekomstbestendige groei veilig te stellen. We helpen klanten niet alleen hun zakelijke doelen te bereiken. Samen verkennen en benutten we de eindeloze mogelijkheden die markten in constante verandering bieden. De springplank voor die visie is talent. Onze campus is onze broedplaats voor innovatie, die een omgeving creëert die talent de ruimte en stimulans geeft die het nodig heeft om te ontkiemen, te ontwikkelen en te floreren. Want werken aan de infinite opportunities van morgen, dat doen we vandaag.
| Coven of Wisdom Herentals
Go to page for Coven of Wisdom - Herentals - Winter `24 editionMastering Event-Driven Design
PLEASE RSVP SO THAT WE KNOW HOW MUCH FOOD WE WILL NEED Are you and your team struggling with event-driven microservices? Join us for a meetup with Mehmet Akif Tütüncü, a senior software engineer, who has given multiple great talks so far and Allard Buijze founder of CTO and founder of AxonIQ, who built the fundaments of the Axon Framework. RSVP for an evening of learning, delicious food, and the fusion of creativity and tech! 🚀 18:00 – 🚪 Doors open to the public 18:15 – 🍕 Let’s eat 19:00 – 📢 Getting Your Axe On Event Sourcing with Axon Framework 20:00 – 🍹 Small break 20:15 – 📢 Event-Driven Microservices - Beyond the Fairy Tale 21:00 – 🙋♀️ drinks 22:00 – 🍻 See you next time? Details: Getting Your Axe On - Event Sourcing with Axon Framework In this presentation, we will explore the basics of event-driven architecture using Axon Framework. We'll start by explaining key concepts such as Event Sourcing and Command Query Responsibility Segregation (CQRS), and how they can improve the scalability and maintainability of modern applications. You will learn what Axon Framework is, how it simplifies implementing these patterns, and see hands-on examples of setting up a project with Axon Framework and Spring Boot. Whether you are new to these concepts or looking to understand them more, this session will provide practical insights and tools to help you build resilient and efficient applications. Event-Driven Microservices - Beyond the Fairy Tale Our applications need to be faster, better, bigger, smarter, and more enjoyable to meet our demanding end-users needs. In recent years, the way we build, run, and operate our software has changed significantly. We use scalable platforms to deploy and manage our applications. Instead of big monolithic deployment applications, we now deploy small, functionally consistent components as microservices. Problem. Solved. Right? Unfortunately, for most of us, microservices, and especially their event-driven variants, do not deliver on the beautiful, fairy-tale-like promises that surround them.In this session, Allard will share a different take on microservices. We will see that not much has changed in how we build software, which is why so many “microservices projects” fail nowadays. What lessons can we learn from concepts like DDD, CQRS, and Event Sourcing to help manage the complexity of our systems? He will also show how message-driven communication allows us to focus on finding the boundaries of functionally cohesive components, which we can evolve into microservices should the need arise.
| Coven of Wisdom - Utrecht
Go to page for Mastering Event-Driven Design