Make a serverless Express API with OpenJS Architect
by Brian Leroux
@brianleroux
on
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:
Or follow these steps to try it yourself from scratch! Node.js is required, but an AWS account is not.
- Create a new Architect app:
npm init @architect ./myexpress
- Add dependencies:
cd myexpress/src/http/get-index npm init --yes npm i express @architect/functions
- 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)
- 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:
- Try out another Begin tutorial, like a full CRUD app with Begin Data!
- 🌟 Check out (and star!) Begin’s open core OpenJS Architect on GitHub