Skip to content

ExpressJS Stack

Express is the most popular web framework for Node. It can be adapted to run on Lambda, making this easy to run locally for development or on AWS for production.

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

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

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.

PackagePurpose
AWS LambdaPlatform
AWS DynamoDBDocument DB, session store, cache
PostgreSQL (available as Aurora Serverless RDS for PostgreSQL on AWS)Relational DB
nussoWebSSO
nusso express middlewareWebSSO
serverless-http for ExpressExpressJS Lambda/API Gateway adapter
Font AwesomeIcons
moment.jsDateTime & timezone manipulation
AxiosHTTP client
node-oracledb *Oracle DB driver
@sentry/nodeError logging
AirBnB eslint rulesCode style
body parserExpress 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:

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 repository 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 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 Linux, 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 package 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.