Porting the app to the MEAN stack

So far the reference application has been built on the Java EE stack for Java EE runtime environments. However, the same application can be build in other programming languages as well.

The MEAN stack consists of MongoDB, Express, AngularJS, and Node JS. Node JS is the main programming platform differentiator.

Porting the reference application consists of two parts: 1) Moving the static UI html and javascript Angular parts to NodeJS, and 2) Re-implementing the REST calls and servlet calls that are used in the controllers.

Part 1 is very easy as the original application was allready based on AngularJS. However there was one issue that needed to be resolved. By default the mongoose framework uses the property names of the documents in MongoDB as properties in the returned JSON objects in the REST API.

This is not always a desired feature. It can be resolved by either changing the AngularJS controller or by using a NodeJS framework that enables aliasing properties in mapping documents to objects.

Porting part 2 will depend on what kind of functionality and functions are used in the business and persistency layers. Implementing the CRUD functions on a MongoDB database using the mongoose and express modules of Node JS is straightforward. The only thing that you need to worry about on Bluemix is that you need to process the database connection details of your service which are available through parsing the VCAP_SERVICES environment variables. This JSON object contains information about the database connection and other services.

var mongoose = require('mongoose');
mongoose.set('debug', true)
var db;
if (process.env.VCAP_SERVICES) {
	   var env = JSON.parse(process.env.VCAP_SERVICES);
	   db = mongoose.createConnection(env['mongolab'][0].credentials.uri);
	} else {
		console.log("creating connection");
		db = mongoose.connect('mongodb://taxreturn:taxreturn@localhost:27017/taxreturns');
}

Now the Bluemix environment with a Java EE and a NodeJS application using the same MongoLab MongoDB instance looks like:Bluemix topology