liveBook · Manning

Express

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

Express is a Node.js web application framework for routing HTTP requests and composing middleware.

Express is a Node.js web application framework for routing HTTP requests and composing middleware. A typical application creates an Express app, registers middleware, defines routes, and listens on a port. section 16.3.2

An Express application can expose routes for an image-processing service:

  • POST /image creates an image process and returns its identifier and initial state. section 16.3.2
  • GET /image/:id retrieves the process state using a path parameter. section 16.3.2
  • POST /image/:id/upload accepts an image upload for the selected process. section 16.3.2

Imagery web service

EC2 instances run Node.js and Express behind a load balancer. Express routes coordinate DynamoDB for process state, S3 for image storage, and SQS for worker processing. section 16.3.2

Listing 16.1 Initializing the Imagery server (server/server.js)
const express = require('express');                      #1
const bodyParser = require('body-parser');
const AWS = require('aws-sdk');
const { v4: uuidv4 }  = require('uuid');
const multiparty = require('multiparty');
  
const db = new AWS.DynamoDB({});                         #2
const sqs = new AWS.SQS({});                             #3
const s3 = new AWS.S3({});                               #4
 
const app = express();                                   #5
app.use(bodyParser.json());                              #6
 
// [...]
  
app.listen(process.env.PORT || 8080, function() {        #7
  console.log('Server started. Open http://localhost:'
 + (process.env.PORT || 8080) + ' with browser.');
});
#1 Loads the Node.js modules (dependencies)
#2 Creates a DynamoDB endpoint
#3 Creates an SQS endpoint
#4 Creates an S3 endpoint
#5 Creates an Express application
#6 Tells Express to parse the request bodies
#7 Starts Express on the port defined by the environment variable PORT, or defaults to 8080

Shows Express application initialization, JSON body parsing, AWS endpoints, and port binding. section 16.3.2

Listing 16.2 Creating an image process with POST /image
app.post('/image', function(request, response) {        #1
   const id = uuidv4();                                 #2
   db.putItem({                                         #3
    'Item': {
      'id': {
        'S': id                                         #4
      },
      'version': {
        'N': '0'                                        #5
      },
      'created': {
        'N': Date.now().toString()                      #6
      },
      'state': {
        'S': 'created'                                  #7
      }
    },
    'TableName': 'imagery-image',                       #8
    'ConditionExpression': 'attribute_not_exists(id)'   #9
  }, function(err, data) {
    if (err) {
      throw err;
    } else {
      response.json({'id': id, 'state': 'created'});    #10
    }
  });
});

Shows a minimal Express POST route that persists an image process and returns JSON. section 16.3.2

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Demonstrates initialization, middleware, route handlers, and responses, but deliberately avoids explaining Express internals in depth.
Examples
Uses image-process creation, state lookup, and image-upload routes as concrete Express examples.
What it assumes
Assumes basic Node.js and dependency usage while leaving deeper Express knowledge unnecessary.
What you can do after
Build a Node.js REST API with Express routes, JSON middleware, AWS-backed persistence, uploads, and a listening server.
How it connects
Connects HTTP routing with Node.js, REST APIs, middleware, DynamoDB, Amazon S3, Amazon SQS, EC2, and load balancing.

Also explained in

Compare how 4 books explain Express →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.