heidloff.net - Building is my Passion
Post
Cancel

Deploying Node Express Apps to OpenWhisk

I’m catching up with all the great new features that have been added to OpenWhisk over the last months. My colleague Lionel Villard published two articles how to run Node Express web applications in a serverless environment. Very cool.

Rather than repeating everything from Lionel’s articles, let me give you a quick summary how this works.

In the OpenWhisk action you use the openwhisk-expressjs module to send a redirect to the Express server.

1
2
3
4
5
6
7
8
const app = require('./server');
const redirect = require('openwhisk-expressjs')(app);

function main(args) {
  return redirect(args);
}

exports.main = main;

In order to make the OpenWhisk action accessible via URL you use web actions. Since the action requires additional node modules, you need to zip everything up first.

1
2
zip -r app.zip
wsk action update api app.zip --kind nodejs:6 -a raw-http true -a web-export true

Since I’ve had some issues to get the sample running, I’ve submitted a pull request. For the time being you can use the extensions I’ve done in my fork.

To run the web application, open the web action URL that you can get from the OpenWhisk dashboard in a browser (without the ‘.json’).

openwhisk-express

Please note that there are limitations as Lionel describes. You shouldn’t host large amounts of static content. However the mechanism above works well for Node applications that use Express to provide REST APIs.

Featured Blog Posts
Disclaimer
The postings on this site are my own and don’t necessarily represent IBM’s positions, strategies or opinions.
Trending Tags