faas

Express middleware for faas.io.

npm install faas
24 downloads in the last week
48 downloads in the last month

faas.io

faas.io is a set of application services to help rapidly develop new apps. It is a cloud development platform that is secure, scalable and reliable.

This npm module augments the faas.io JS library to provide foundation services on the server side.

Installation & Setup

First, install the library in your node project:

npm install faas --save

In order to have the best experience with faas.io, it is recommended that you simply make the faas.io tools available globally (and use a capitalization convention to make it stand out).

global.Faas = require('faas');

You should do this at the top of your main app entry point, probably app.js.

If you prefer not to use global settings like that, you are free to include (require) the faas module in any file as you would normally with nodejs.

faas.io provides several useful tools to help you out. Here's a recommended setup to get the most out of Faas:

global.Faas = require('faas'); // Load the toolbox.

// Configure it with your credentials.
Faas.config({
  apiKey: '<<< YOUR FAAS API KEY >>>',
  apiSecret: '<<< YOUR FAAS API SECRET >>>'
});


// Use the Faas env config service to help with cumbersome app setup.

Faas.env(function(){

  // Initialize your app.

  var express = require('express');
  var app = express();

  app.set('port', Faas.env.PORT); // <-- Example Faas.env usage here.

  app.use(express.cookieParser(Faas.env.COOKIE_SECRET)); // <-- And here.

  // Use the Faas middleware for user authentication.
  app.use(Faas.io());

  // ... other app code ...

  // Start your app.
  require('http').createServer(app).listen(app.get('port'));
})

Check out the docs for the individual Faas services to learn more about how each of them can save you time and effort.

Usage

=== User Authentication

In your main node.js Express application file (e.g. app.js), add the faas middleware. The application credentials are available on your Dashboard when you register.

...

app.use(express.session());
app.use(Faas.io()); // <-------- Insert this code
app.use(app.router);

...

In your server side code (e.g. Express routes), the securely verified faas.io elements are available in the request session.

req.sesssion.faas.username
req.sesssion.faas.session_id

Use these variables to build user-specific application logic.

=== Environment configuration

Call Faas.env(callback) to get access to a highly configurable environment settings service, featuring cascading settings and multiple inheritance. By the time the callback is fired, Faas.env will be loaded with the appropriate settings for your environment, including settings that are specified in your process.env. You can switch which group of settings you want to use via the FAAS_ENV variable, e.g.:

FAAS_ENV=staging node app.js
npm loves you