DEV Community

Cover image for Build an HTTP server in Bun

Build an HTTP server in Bun

Sadeedpv🥇 on September 19, 2023

As of last week, Bun has taken over the JavaScript world. In this post, we will see how to create an HTTP server in Bun using the Elysia Framework....
Collapse
 
lvndry profile image
Landry Monga

Just FYI you can use Response.json this will automatically do the parsing and set the headers

Collapse
 
sadeedpv profile image
Sadeedpv🥇

oh, thank you I didn't know that 😄🙌!

Collapse
 
rampa2510 profile image
RAM PANDEY

Have you encountered any challenges while migrating an Express application to Elysia? If so, could you share your experiences and any obstacles you encountered? I'm curious about whether Elysia can seamlessly replace Express, especially regarding middleware compatibility, configuration options, and any limitations you might have come across.

Collapse
 
sadeedpv profile image
Sadeedpv🥇

Middlewares in Elysia is a bit different compared to Express. See if this helps

Collapse
 
marmeden profile image
eneasmarin

I was considering building this server using purely Bun.js. Saw some tutorials where they were handling routes simply by using 'ifs' inside the Bun.serve block and was not very convinced about that because it looks untidy, but wouldn't like to use extra dependencies like Elysia, Hono, Express...

Is it possible to do it using only Bun.js? What are the drawbacks? Why using Elysia, Hono, Express is better?

Collapse
 
sadeedpv profile image
Sadeedpv🥇 • Edited

Most of the time, it is better to build stuffs without the use of a framework unless you have specific reasons to. But, like you said, in this case, it can make your code a bit untidy. That's where frameworks come in. Using a framework like Elysia for example, can help to speed up the development process. Also, as shown in the graph above, Elysia claims to be much faster than any other frameworks. But, if you can build things without the need of a framework, go for it 👍

Collapse
 
bob4262 profile image
Bob dnaeil

I was looking for this tutorial just now, thnks

Collapse
 
sadeedpv profile image
Sadeedpv🥇

You are welcome!

Collapse
 
schwiftycold profile image
Shubham Kumar

So the future of JS runtime is Bun :love:

Collapse
 
sadeedpv profile image
Sadeedpv🥇

💘💘

Collapse
 
bob4262 profile image
Bob dnaeil

Really helpful ❤️

Collapse
 
jerommiole profile image
jrom

I'm glad that I saw this 😁

Collapse
 
sadeedpv profile image
Sadeedpv🥇

Glad you liked it!

Collapse
 
astrodev07 profile image
Diego Enríquez Puig

Too many Runtimes and JS frameworks. My mind is exploding XD

But is good to know that the technology advances so fast

Collapse
 
sadeedpv profile image
Sadeedpv🥇

🥲🥲