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.
Join the DZone community and get the full member experience.
Join For Freei’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’.
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.
Published at DZone with permission of Niklas Heidloff, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments