Creating HelloWorld for Node.js with MongoDB Application Template

All actions will be performed in Design Studio workplace.

Creating Prerequisites

Creating Service Type

  1. Click on Services view and Service Types tab.

  2. On the Activities ribbon, click on Add Service Type and enter the settings:

    • Name - put helloworld_mongodb_app
    • Product Vendor - put vixtera
    • Category - click Browse and choose the application category Web Application
    • OS Family - click Browse and choose Linux
    • Description - put HelloWorld Application with MongoDB

Creating Application

  1. Create a folder package and a file named helloworld_mongodb.js with the following content:
// Load configuration
var config = require('./config.json');

// Connect to database
var MongoClient = require('mongodb').MongoClient;
var assert = require('assert');

var url = config.database.scheme + '://' + config.database.user + ':' + config.database.password +'@' + config.database.host + ':' + config.database.port + '/' + config.database.name;
var message;
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  var cursor = db.collection('helloworld').find( );
  cursor.each(function(err, doc) {
    assert.equal(err, null);
    if (doc != null) {
      message = doc.message;
    }
    db.close();
  });
});

// Load the http module to create an http server.
var http = require(config.server.protocol);

// Configure HTTP server to respond with message to all requests.
var server = http.createServer(function (request, response) {
  response.writeHead(200, {"Content-Type": "text/plain"});
  response.end(message + "\n");
});

server.listen(config.server.port);

// Configure graceful shutdown
process.on('SIGTERM', function () {
  server.close(function () {
    process.exit(0);
  });
});
  1. In package folder, create a folder node_modules and download there the mongodb module for node.js. This may be done executing npm install mongodb
  2. Compress package folder to archive helloworld_mongodb.tgz
  3. Create a folder application and put there the archive helloworld_mongodb.tgz.
  4. Create a folder scripts and a file named helloworld.json with the following content:
{"_id":{"$oid":"56f924fe13c01e5ce9712ac5"},"message":"Hello World"}
  1. Compress application and scripts folders to archive helloworld_nodejs_mongodb.zip

Creating Application Template

  1. Click on Services view and Application Templates tab.

  2. On the Actions ribbon, click on Add Template and Add Template.

  3. In the General section configure Properties.

    • Version - click on Browse, and specify the following:

      • Service Type - click on Browse and select the application type helloworld_mongodb_app.
      • Major - put 1 and leave 0 for Minor, Maintenance ID, Build #
    • Display Name - put HelloWorld for Node.js with MongoDB 1.0.0.0

    • Description - HelloWorld Web Application for Node.js with MongoDB.

  4. In the Service Management section click on Topology. From the Topology Components pane, from sections Web Platforms > nodejs_mongodb_platform drag and drop Node.js and MongoDB Web Platform 1.0.0.0 template to the topology workspace.

  5. In the Service Management section, click on Services. Select service Node.js 1.0.0.0 and click Customize Settings.

    • In the Service Management section, click on Service Parameters.

      • Click on Add Parameter and configure the following:

        • Name - put application
        • Default Value - put helloworld_mongodb
        • Mark the Required checkbox
        • Description - put Node.js application name

        Click OK.

      • Click on Add Parameter and configure the following:

        • Name - put package
        • Default Value - put helloworld_mongodb.tgz
        • Mark the Required checkbox
        • Description - put Node.js application package name

        Click on OK.

  6. Select service MongoDB 1.0.0.0 and click Customize Settings.

    • In the Service Management section, click on Service Parameters.

      • Click on Add Parameter and configure the following:

        • Name - put script
        • Default Value - put helloworld.json
        • Mark the Required checkbox
        • Description - put Data file name

        Click OK.

  7. In the Service Management section, click on Deployment Profiles. Click on Add Deployment Profile and configure the following:

    • In the General section, click on Properties:

      • Name - put testing.
      • Environment Type - click on Browse and select Testing.
      • Description - put All-in-one deployment with minimal hardware resources.
    • In the General section, click on Deployment Diagram:

      • Drag and drop service Node.js 1.0.0.0 to the workspace. Ensure that Hardware Platform is Tiny and click on OK.
      • Drag and drop service MongoDB 1.0.0.0 to the same Deployment Group Node.js.
    • Click on OK

  8. In the Media section, click on Customization Project.

    • Click on Add Folder Mapping and set:

      • Source Project Folder - put application
      • Target Media Folder - select application

      Click on OK

    • Click on Add Folder Mapping and set:

      • Source Project Folder - put scripts
      • Target Media Folder - select scripts

      Click on OK

    • Click Upload near to Customization archive field and set:

      • File Name - click Browse and locate the file helloworld_nodejs_mongodb.tgz
      • Source Folder - automatically set

      Click on OK.

  9. Click on OK.

Testing Application Template

  1. Click on Services view and Application Templates tab.

  2. Select template HelloWorld for Node.js with MongoDB 1.0.0.0 in the Application Templates grid.

  3. On the Actions ribbon, click on Test Template.

  4. In the Provisioning section, click on Properties and set:

    • Environment Type - click on Browse and choose Testing
    • Space, Deployment Profile and System Profile will be completed automatically
  5. Click on Provision.

  6. Click on OK.