Make a serverless Express API with OpenJS Architect

avatar
Brian Leroux
February 11, 2020

Express train Photo by Fikri Rasyid

It’s finally possible to transition your Express apps to a fully serverless architecture with just a few lines of code.

Hit this button to deploy a Hello World! app that uses Architect’s new Express migration middleware; it’ll take about 15 seconds:

deploy-to-begin

Or follow these steps to try it yourself from scratch! Node.js is required, but an AWS account is not.

  1. Create a new Architect app:
npm init @architect ./myexpress
  1. Add dependencies:
cd myexpress/src/http/get-index
npm init --yes
npm i express @architect/functions
  1. Express yourself 💅🏾
// src/http/get-index/index.js
let arc = require('@architect/functions')
let express = require('express')
let app = express()
app.get('/', (req, res) => res.send('Hello World!'))
app.get('/cool', (req, res)=> res.send('very cool'))
exports.handler = arc.http.express(app)
  1. Start the local server with npm start and enjoy!

⚠️ Note: Bundling an entire app with a web server in a Lambda function will result in poor performance if the entire function’s payload (including dependencies) exceeds 5MB.

Next Steps

Pretty neat, right? If you didn’t do it already, try it for yourself in 15 seconds: click the button below to deploy a Hello World! app that uses Architect’s new Express migration middleware:

deploy-to-begin