ExpressJS Stack

Expressopen in new window is the most popular web framework for Node. It can be adapted to run on Lambdaopen in new window, making this easy to run locally for development or on AWS for production.

Getting Started

A template with an included IaC module for deploying to AWS is available in the Northwestern github organizationopen in new window. This template is suitable for a microservice project.

You can create a new repository using this template from GitHub's new repository page.

Stack

Express is a minimalistic framework. It does not bring its own opinions about libraries & design patterns to the table, leaving these up to the developer. Below are the libraries that are recommended for various purposes. When applicable to an application, these should be used.

The Administrative Systems Seal of Approval

These serve as a good set of "default" options for things.

There may be use-cases where something else is better, but unless & until a justification can be made to use something else, you should draw from this list.

Using the same libraries will allow AS developers to transfer between projects more easily, as technical competencies developed in one project will be transferrable to other projects.

PackagePurpose
AWS LambdaPlatform
AWS DynamoDBDocument DB, session store, cache
PostgreSQL (available as Aurora Serverless RDS for PostgreSQL on AWS)Relational DB
nussoopen in new windowWebSSO
nusso express middlewareopen in new windowWebSSO
serverless-http for Expressopen in new windowExpressJS Lambda/API Gateway adapter
Font Awesomeopen in new windowIcons
moment.jsopen in new windowDateTime & timezone manipulation
libphonenumberopen in new windowPhone number info & validation
Axiosopen in new windowHTTP client
node-oracledbopen in new window *Oracle DB driver
@sentry/nodeopen in new windowError logging
AirBnB eslint rulesCode style
body parseropen in new windowExpress middleware to parse HTTP request body
* See the section below on setting up the Oracle driver.

† Sentry recently released @sentry/serverless for NodeJS on Lambda. This package has not yet been evaluated.

There is currently no consensus on a JS testing framework. ADO has used the following successfully:

Code Style & Linting

The airbnb-base set of rules for eslint should be used to ensure source code is formatted the same and complies with the same set of rules.

The template repositoryopen in new window already has eslint set up. If you need to add this to an existing project:

  1. Add the packages as dev dependencies:

    yarn add --dev eslint eslint-config-airbnb-base eslint-plugin-import

  2. Create a .eslintrc.js file in the root of your project:

    module.exports = {
        "extends": "airbnb-base",
        "env": {
            "node": true,
            "es6": true,
            "mocha": true
        },
        "rules": {
            "no-console": "off",
            "max-len": "off"
        }
    };
    
  3. Ensure your editor of choice has integration with eslint installed

Oracle on AWS Lambda

Oracle provides a node package wrapping their driver. Setting it up is not difficult, but it is more involved than a simple yarn add.

  1. Create a lib/ folder, get the Oracle basic instant client for Linuxopen in new window, and unzip it.

    The lib/ folder should have several .so files in it now.

  2. Add the highlighted directories section below to your package.json:

    {
        "name": "demo-project",
        "version": "0.0.1",
        // etc etc
        "directories": {
            "lib": "lib"
        },
    }
    




     
     
     

  3. Add the oracledb packageopen in new window as a dependency

    • Yarn will build the C++ extension against the instant client libs
  4. Add some env vars to the run scripts in the package.json so the app looks for for the Oracle libs in lib/:

    cross-env PATH=\"$PATH:./lib\" LD_LIBRARY_PATH=\"./lib\" nodemon -L ./bin/www

    This example is launching the app with nodemon, but the command after the two env variables depends on how you are running your code.

  5. Check the Linux lib/ into git

    MacOS & Windows users could run this locally by adding their platform's Oracle drivers. It is not advisable to add the instantclient for Windows or MacOS to git, as the files are very large.

    If you are on Windows or Mac, you will need to download the basic instant client zip file. On Windows, you can unpack it into the lib/ folder. On Mac, you will need to unpack it to ~/lib, outside of the project directory. On both operating systems, it should be automatically detected when you run the app.