Express for Junior Developers Like Me

This series will be a quick and dirty, extremely simplistic overview of Express, a framework for Nodejs. The goals of the guide are to:

  • How to setup Express
  • Explain it’s basic parts
  • Talk about app structure

Part of the reason I’m writing this is to reinforce my own junior knowledge of the subject. Sometimes we forget how to explain things as we get better at them. Writing this now allows me to speak in a language students at my level of understanding can grasp. So, hopefully this guide will be helpful for other junior developers trying to wrap their minds around Express.

On with the show!

The Basics

When building an app, we’re dealing with four main components:

  1. The app itself (express).
  2. Routes
  3. Middlewares
  4. Handlers

In a sense, breaking this into four parts is somewhat redundant, as they’re integral to one another (no single one of these things is useful without the others). But it’s good to understand these parts separately.

Routes handle browser requests. They literally route the user from one area of the app to the other. To map out the areas of the app we have Middlewares. These are tiny modules that perform very, very specific tasks for the app. As an example, bodyParser helps our app manipulate the DOM, which allows us to manipulate the webpage. And that leads us to Handlers. These are the actual instructions to manipulate that webpage. We see them most commonly as javascript functions throughout the app.

These three parts make up the app itself. Express provides a framework for communication between the client and the server.

Every application we make has to perform these tasks. We have to present the user with the app, allow them to manipulate the app, and provide instructions between the browser and server for those interactions. That may sound like a mouthful, but it’s pretty simple. Express is just a layer between the browser and the server.

Reading the documentation for Express isn’t as intimidating as the idea sounds. Usually I read documentation for things like this and it just obfuscates the essential facts. In this case, the developers of Express do an amazing job of keeping the instructions extremely short, but also extremely clear and easy to read. I highly recommend reading the documentation before creating any new applications with Express. Having that level of understanding is super useful when digging through files trying to set-up your app. It’ll save you some sweat and tears.

No guide is complete without some code. Here’s a complete Express app.

 

Leave a Reply

Your email address will not be published. Required fields are marked *