Is Express the best back-end framework for your app?

Kate Davis
4 min readMay 3, 2021

Express JS has come to be the most popular web application framework for Node.js. But how does it compare to its predecessor, Sinatra, or newer Node.js frameworks like Koa?

Express JS

Express is a light-weight, open-source web application framework for Node.js that allows for quick and easy development with full control of request and response. It can be used for server-rendered apps, as well as RESTful API/Microservices.

Due to its minimalistic style, with support for extensive middleware, it allows for a lot of freedom. Like most web app frameworks, Express offers libraries that handle essential development concerns like authentication, data validation, templating, etc.

Let’s take a look at how to make a simple Express app:

‘Hello World’ app from Express JS documentation

Here we require Express, initialize Express and assign it to a variable, app, create an endpoint/route handler with a method, url and callback, and instruct the server to listen on a port of our choice.

Pros

  • It’s easy to get started and has comprehensive documentation to reference
  • Due to its maturity it is more stable than most competitors
  • Has extensive middleware ecosystem

Cons

  • No single recommended way of doing things can cause confusion or disorganization

If you’re working with Javascript, and looking for a flexible framework with lots of documentation, Express could be the pick for you

Sinatra

Sinatra is a DSL (domain specific language) for creating web applications in Ruby, and its light framework and style is the inspiration for Express. It’s a Ruby-based framework built on top of Rack: a modular, Ruby web server interface. Its minimalist build allows for quick server setup. This same basic ‘Hello World’ app takes fewer lines of code than in Express:

‘Hello World’ app from Sinatra documentation

The Sinatra route pairs an HTTP method with a URL matching pattern and associates it with a block of code.

Pros

  • Provides the bare minimum needed for development so that you can easily access essential components without the bulk of extras
  • Few dependencies make for quick loading time

Cons

  • The Rack has less available middleware than Express
  • Not scalable due to minimalistic design

If you’re familiar with Ruby, don’t need as much freedom, and want a quick, light-weight, no-frills framework, Sinatra could be the pick for you

Koa

Koa is a next generation web application framework built by the team behind Express. It’s more lightweight than Express and replaces callbacks with async functions, allowing for even more concision. It contains an extensive array of middleware functions, which are not bundled, resulting in a smaller footprint. Check out how the same simple Hello World app can be initiated:

‘Hello World’ app from Koa documentation

We require Koa, initialize Koa and assign it to a variable, app, call app.use with an async function that sets the context body to our string. Express’s request and response objects are replaced with Koa’s context object. It provides a number of methods (along with ctx.request and cxt.response) that contain automatic delegation to request or response objects.

Pros

  • Designed for flexibility and ease of writing custom middleware
  • Replacement of callbacks with async
  • Increased error handling

Cons

  • Less mature framework results in less stability than Express, fewer resources, and less support

If you’re comfortable writing custom middleware, with less guidance and support, your project can benefit from Koa’s eloquence, concision, and error-handling

Choosing libraries

With the advent of light-weight frameworks and the freedom to choose supplementary libraries, comes the dilemma of how to choose. Here are some points to consider:

  • What language is the library written in? What degree of compatibility does it have with your project?
  • How is the quality of the documentation and available resources?
  • How frequent and recent are git commits on the library repository? This can provide evidence that patches are up to date, and that support is available if you run into any bugs.
  • Size: Ideally you want to maintain a balance between having your needs covered, without bloating the project with unnecessarily large libraries.

As always, in the quest for an ideal back-end framework and supporting libraries, IT DEPENDS on the needs of your project!

Resources:

--

--