node package manager


FeedHenry REST API routes

fh-webapp is part one of a two-part replacement for fh-nodeapp. Webapp is the "'"hostapp" part of fh-nodeapp, that which makes public endpoints from exported functions in cloud/main.js. It also hosts some system-level piping to help the studio determine if an app is online, the endpoints it exposes), and introduces a new namespace - /mbaas.


Add the following to the 'dependencies' section of your 'cloud/package.json' file:

"fh-webapp" : "*",
"fh-api" : "*",
"express" : "3.3.4"

Add a file to your FeedHenry app 'cloud/application.js', with the following contents:

var webapp = require('fh-webapp');
var express = require('express');
$fh = require('fh-api');
var mainjs = require('main.js');

var app = express();
app.use('/sys', webapp.sys(mainjs));
app.use('/mbaas', webapp.mbaas);

// You can define custom URL handlers here, like this one:
app.use('/', function(req, res){
  res.end('Your Cloud App is Running');

module.exports = app.listen(process.env.FH_PORT || process.env.VCAP_APP_PORT || 8001);

The above application.js is just an Expressjs application - it's easily extensible.

You can create custom API handlers in the Express format by doing:

app.use('/myapi', function(req, res){
  res.end('My custom response');

Express has a built-in static file server. In this example, we host files under the public directory:

app.use(express.static(__dirname + '/public'));


(POST | GET | PUT) /cloud/:someFunction

Authentication : Optional - can be enabled globally or on a per-endpoint basis under "Endpoints" section of the studio. Response formats : JSON, binary, plain text

x-fh-auth-app : API key of your application, found under the "details" section of the studio.

JSON format - paramaters to be passed to the exported function, see 'Writing API Functions'.

Result as passed to the callback function of the exported function - see 'Writing API Functions'.

The cloud namespace exposes the public functions of a javascript file of your choice (traditionally 'main.js') as public endpoints under the cloud URL namespace. :someFunction is the name of a function attached to the 'exports' object. These functions take two paramaters - the first is the data sent in the POST, the second is the callback function to call.

exports.getConfig = function (params, callback){
  // Do some work here, then return data
  var err = false;

  // Check if some error condition happened first
  if (err){
    return callback(err);
  return callback(null, res);

POST /mbaas/db

Authentication : Required - App API key goes here. Response format : JSON

x-fh-auth-app : API key of your application, found under the "details" section of the studio.

POST Body:

JSON body - same as $fh.db params. A summary of body options follows - For more, see $fh.db docs

    "act": "create|update|list|delete|deleteall",
    "type": "collectionName",
    "guid": "GUID of object operating on - not required for list or deleteall",
    "fields": "JSON definition of fields - required for create|update",
    "eq|ne|in" : "JSON definition of query to match - supported for list only"

As per $fh.db

Authentication : None Response formats : Plaintext



if application is running as expected. Will respond with a 404 otherwise

Authentication : None Response formats : JSON


  endpoints : ['array of endpoints exported as public functions']

Authentication : None Response formats : JSON


  rss: 13721600, // Resident set size
  heapTotal: 7195904, // V8's total available memory
  heapUsed: 2369744  // V8's used memory

Authentication : None Response formats : Plaintext