codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Follow publication

Member-only story

Let’s build a REST API with Koa.js and test with Jest!

Jared Nutt
codeburst
Published in
9 min readSep 21, 2018

Background

Up and until recently I’ve been using express for my node routes. It’s been a good run, but I’m here to tell you that Koa is superior.

From their website.

Koa is a new web framework designed by the team behind Express, which aims to be a smaller, more expressive, and more robust foundation for web applications and APIs. Through leveraging generators Koa allows you to ditch callbacks and greatly increase error-handling. Koa does not bundle any middleware within core, and provides an elegant suite of methods that make writing servers fast and enjoyable.

What I love about it

  1. The whole framework is built on async/await
  2. It brings practically nothing other than basic routing, so that makes it incredibly light-weight.
  3. It was built by the express people as a replacement.
  4. Simplest error Logging I’ve ever seen.

Koa vs Express

I’m not going to sit here and babble on about it, when much smarter people have talked about it, here and here.

Alternatively, if you don’t want to read this at all, and just want to see the final code, check out the repo:

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in codeburst

Bursts of code to power through your day. Web Development articles, tutorials, and news.

Written by Jared Nutt

Freelance web developer living in Los Angeles. I write articles I wish I had when I was learning — mostly about Javascript and web development.

Responses (5)

Write a response

Great article Jared! Really helpful and complete. Thank you bro (fist emoji).

--

nice and helpful

--

Hi Jared, i have an issues, i hope you can help me a little, when I run the test, I received this: TimeoutError: ResourceRequest timed out, with a 500 status code, and I tested this route and work find.
Thanks

--