Sitemap
Ben Hood

Ben Hood

Express vs The World

5 min readJul 12, 2024

--

Express, running atop Node.js, stands as one of the most prevalent backend frameworks globally. What makes Express so compelling, and how does it stack up against its backend counterparts? Let’s delve into the nuances and merits of this influential framework.

Press enter or click to view image in full size
Graph from Stack Overflow’s 2023 Developer Survey, showing Express in 4th place overall for framework popularity
Overall standings of most popular web frameworks and technologies

According to the Stack Overflow 2023 Developer Survey, it boasts usage by 19.51% of professional developers and is a preferred choice for 20.8% of coding enthusiasts.

Why should you use a framework for your backend?

Writing the backend of an application in plain vanilla code is draining. Without a framework you would need to write a ton of boilerplate code to handle common tasks such as routing, parsing request bodies, managing sessions and handling errors. This would lead to a large, repetitive codebase and make it difficult to scale. When writing code, we are always aiming for readability, maintainability and scalability, and without using a framework, it becomes very difficult to keep the latter two. Here is an example of basic routing, written in vanilla Javascript:

const server = http.createServer((req, res) => {
const parsedUrl = url.parse(req.url, true);
const path = parsedUrl.pathname;
const method = req.method.toLowerCase();

if (path === '/' && method === 'get') {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('You have reached the homepage!');
} else if (path === '/api' && method === 'get') {
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ message: 'I am your API!' }));
} else {
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404: Not Found');
}
});

By using a framework, many of these issues are already solved for you, meaning you can spend more time cracking that horrid bug that you have been working on for hours.

Here is an example of the same routing, written using Express:

const app = express();

app.get('/', (req, res) => {
res.send('You have reached the homepage!');
});

app.get('/api', (req, res) => {
res.json({ message: 'I am your API!' });
});

Shorter, more readable and less repetitive, right?

Popular backend frameworks

Here are the most popular frameworks by language:

Javascript: Express
C#: ASP.NET
Python: Flask
Java: Spring Boot
PHP: Laravel

These backend frameworks all essentially do the same thing, helping developers build robust and scalable backend applications.

So, why would I choose Express?

Well, that largely depends on the programming language you are using. If you are coding in C# or Python, you wouldn’t naturally opt for Express when there are robust frameworks available in your language of choice. Learning an entirely new language just for a framework might not be necessary.

Each framework has its own set of advantages and drawbacks. Flask, for example, is excellent for quick starts but lacks built-in security features and scalability for larger applications. Spring Boot is praised for its easy setup and deployment but can be complex to master. Laravel offers robust built-in features, albeit in PHP (no offense to PHP developers!).

Express, on the other hand, shines with its lightweight nature, seamless routing, and impressive performance. However, it comes with a steeper learning curve compared to frameworks like Ruby on Rails or Django as it requires more manual configuration and a good understanding of JavaScript and Node.js concepts (such as callbacks, promises, async/await).

If Express has as many drawbacks as other frameworks, why is it so popular?

Simple answer: Express is one of the most minimal, flexible and resourceful backend frameworks and Node.js is the single most popular backend runtime technology in the world right now, running off of the most widely used programming language in the world, Javascript.

Get Ben Hood’s stories in your inbox

Join Medium for free to get updates from this writer.

This popularity has helped Express to gain a large and active community of developers, meaning there are ample resources, tutorials and community support available to learners, meaning at the rate it is growing, there is no end in sight for Express.

The widespread adoption of the MERN stack — comprising MongoDB, Express, React, and Node.js — further underscores Express’s credibility. Companies like Netflix, Airbnb and Walmart utilize this stack for its scalability and efficiency, validating Express’s capability. As Express continues to evolve and expand, its future looks promising, with no sign of slowing down. However, new frameworks such as Koa and Hapi are entering the Node.js realm and may present compelling competition for Express.

Comparison of Node.js frameworks: Express vs Koa

Express and Koa are both popular Node.js frameworks used for building web applications, but they differ significantly in their designs and approaches. Let’s explore how they compare in key areas:

Middleware

  • Express: Uses a stack-based middleware approach where middleware functions are executed sequentially. This creates a straightforward way to handle requests and responses.
  • Koa: Uses a modern and lightweight middleware approach based off of async/await. This allows for more readable asynchronous code handling, with better error handling built-in.

Performance

  • Express: Due to its simplicity and wide use, Express has been optimized and is known for its high performance in handling HTTP requests, however some newer frameworks such as Koa and Fastify are able to handle more requests per second.
  • Koa: With it’s minimalistic middleware handling and lightweight design, Koa may offer higher performance in scenarios where there is heaving asynchronous operations.

Learning Curve

  • Express: Usually considered easier to learn due to the extensive documentation and community that offers more resources and tutorials. Express also has a straightforward API.
  • Koa: If you are not comfortable with ES6 generators, Koa can have a steep learning curve, however if you already have familiarity with these concepts, Koa encourages efficient and modern coding.

Community

  • Express: Boasting one of the largest communities of any framework due to it’s popularity, Express offers large resources, middlewares and plugins.
  • Koa: Due to being relatively new to the scene, Koa doesn’t have quite as large a community as Express, however as more developers adopt the framework due to it’s lightweight and modern nature, this community is rapidly growing and the tools and libraries are growing to match.

The Bottom-line

Express is undeniably attractive, especially for beginners learning JavaScript as their first programming language (unless you’re specializing in game development or database engineering). It’s likely to be one of the first frameworks you’ll encounter. New frameworks are on their way up the foodchain but until another framework revolutionizes the landscape (the way React did for everyone on the front end), Express will likely remain a staple in the programming world.

References:
Stack Overflow 2023 Developer Survey
What is the MERN stack
Koa
Express

--

--