A Straightforward Guide to Back-End JavaScript

This is how you get data to a user.

generated using InvokeAI with the stable-diffusion-xl model; real people, construction workers starting work on a skyscraper, in the style of a miniature model, shallow dof, tilt shift, high contrast, ultra detail, natural lighting

Unless you want a static site, you need some way of reading/writing/updating user data. This is commonly built using a back-end/front-end framework.

Front-end frameworks attract most of the headlines. If you’ve heard of Vue, React, UIKit, Nuxt…these are all front-end frameworks (or libraries). But these need back-end data in order to be useful.

The structure will typically look something like this:

A very basic diagram showing the data flow from the database to the cloud and user application.

The focus of this article will be on the yellow part and the lavender part.

While it’s not the only stack to use, I’ll show you how to set up a backend stack using the following framework:

  • Knex for communicating with the database
  • Express for handling the routes/views.

For this back-end we’ll be focusing on returning JSON data. For example, if we want to get a user, we can perform the following query (using the CURL command line):

$ curl -X GET http://example.com/users/1
{
"id": 4,
"username": "johnsmith",
"email": "john@example.com",
}
$…

--

--