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.
Getting Started
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.
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.
Package | Purpose |
---|---|
AWS Lambda | Platform |
AWS DynamoDB | Document DB, session store, cache |
PostgreSQL (available as Aurora Serverless RDS for PostgreSQL on AWS) | Relational DB |
nusso | WebSSO |
nusso express middleware | WebSSO |
serverless-http for Express | ExpressJS Lambda/API Gateway adapter |
Font Awesome | Icons |
moment.js | DateTime & timezone manipulation |
Axios | HTTP client |
node-oracledb * | Oracle DB driver |
@sentry/node † | Error logging |
AirBnB eslint rules | Code style |
body parser | Express 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 repository already has eslint set up. If you need to add this to an existing project:
Add the packages as dev dependencies:
yarn add --dev eslint eslint-config-airbnb-base eslint-plugin-import
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" } };
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
.
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.Add the highlighted
directories
section below to yourpackage.json
:{ "name": "demo-project", "version": "0.0.1", // etc etc "directories": { "lib": "lib" }, }
Add the
oracledb
package as a dependency- Yarn will build the C++ extension against the instant client libs
Add some env vars to the run scripts in the
package.json
so the app looks for for the Oracle libs inlib/
: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.Check the Linux
lib/
into gitMacOS & 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.