Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Deploying Node Express Apps to OpenWhisk

DZone's Guide to

Deploying Node Express Apps to OpenWhisk

Want to know how to run an Express app in a serverless environment? Curious about OpenWhisk? Let's cover the advantages and challenges involved.

· Cloud Zone ·
Free Resource

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

I’m catching up with all the great new features that have been added to OpenWhisk over the last few 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.

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.

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 getting 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.

Site24x7 - Full stack It Infrastructure Monitoring from the cloud. Sign up for free trial.

Topics:
openwhisk ,express ,node.js ,apps ,deploy ,serverless

Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}