liveBook · Manning

Express

As explained in Building User-Friendly DSLs

A Node.js web application framework for building HTTP servers and routing web requests.

Express is a Node.js framework for building a small REST backend with minimal configuration. It creates an HTTP server, maps routes, returns JSON, and can serve frontend files. section 7.1

A minimal Express backend follows these implementation steps:

  • Install the dependency with npm install express. section 7.1
  • Create an application, define GET /contents, and return stored data with response.json. section 7.1
  • Start the server on port 8080 and verify it at http://localhost:8080/contents. section 7.1
  • Serve the frontend dist/ directory as static content so frontend and backend share an origin. section 7.1

JSON backend for a rental AST

A storage module reads and writes contents.json. Express exposes the stored rental example through GET /contents, while the frontend fetches that endpoint and renders the returned JSON. section 7.1

Listing 7.4 Code to start an Express server in src/backend/server.js
const { readContents } = require("./storage")    #1
let contents = readContents() 

const express = require("express")      #2
const server = express()                   #3

server.get("/contents", (request, response) => {        #4
    response.json(contents) 
}) 

// TODO  add PUT code                   #5

// TODO  add static serving code       

const port = 8080 
server.listen(port, () => {          #6
    console.log(`Server started on: http://localhost:${port}`) 
})

Inspect the complete server setup, including storage loading, the JSON route, the port, and placeholders for future PUT and static-serving code. section 7.1

How Building User-Friendly DSLs covers it

How deep it goes
Explains installation, application creation, routing, JSON responses, startup, and static serving, but leaves PUT handling as future work.
Examples
Uses contents.json, a rental AST, GET /contents, port 8080, and static serving of the dist/ directory.
What it assumes
Assumes basic Node.js, npm, JavaScript modules, JSON, and frontend fetching; demonstrates the server setup explicitly.
What you can do after
Build it from scratch as a Node.js server that returns JSON and serves a frontend.
How it connects
Connects Express with Node.js, REST, HTTP servers, JSON, frontend fetching, Parcel, and CORS.

Also explained in

Compare how 4 books explain Express →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.