Quantcast
Channel: Languages – AMIS Technology Blog | Oracle – Microsoft Azure
Viewing all articles
Browse latest Browse all 163

Deploying an Oracle JET application to Application Container Cloud and running on Node.js

$
0
0
Share this on .. Tweet about this on TwitterShare on LinkedInShare on FacebookShare on Google+Email this to someoneShare on TumblrBuffer this page

An article from the Oracle A-Team (http://www.ateam-oracle.com/oracle-jet-with-nodejs/) describes how to run a sample Oracle JET application on a Node.js server. I have followed the steps in that article, ran the JET application locally and then configured the application for deployment to the Oracle Application Container Cloud. Subsequently, I created a new application on that cloud based on the application archive for the JET application and accessed the application. This article briefly describes the steps I went through. It should make clear how to get JET applications to run on the Oracle Application Container Cloud.

image

The steps in short are:

  • install Node.js – which includes npm, the Node Package manager
  • install express using npm
  • install express-generator using npm
  • generate the oraclejetwithnodejs application scaffold using express
  • add dependencies using npm
  • download the Oracle JET Starter Template Quickstart sample application ZIP file and extract the contents into the oraclejetwithnodejs application directory structure
  • create a small JavaScript file (partials.js), make some small modifications in another JavaScript file (app.js) and move a directory
  • run the application locally to verify it is working correctly
  • create file manifest.json that is required by the Application Container Cloud
  • create an application archive (zip file) for the entire oraclejetwithnodejs application
  • created a new application on the Application Container Cloud based on that application archive for the JET application
  • access the application from any browser anywhere in the world

It turns out that the steps that are really specific for the Application Container Cloud are minuscule: the last four bullets in this list. It is extremely simple, in short, to run an Oracle JET application on Node.js and subsequently in a Node.js container in the Application Container Cloud.

Prepare for a new Node.js Environment and a fresh Application

Following the instructions in the article from the Oracle A-Team (http://www.ateam-oracle.com/oracle-jet-with-nodejs/), I have through these preparatory steps:

  • install Node.js – which includes npm, the Node Package manager; in my case I downloaded Node.js for Windows from the Home of Node.js. Probably even easier would have been to work with a Docker Container image with a Node.js environment set up.
  • install express using npm (npm install express –save)
  • install express-generator using npm (npm install express-generator -g)
  • generate the oraclejetwithnodejs application scaffold using express (express oraclejetwithnodejs)
  • add dependencies using npm (npm install)

At this point, a directory structure has been created with the basic scaffolding for the new Node.js application, called oraclejetwithnodejs. Nothing has been done that is specific to Oracle JET.

The application – while still bare – can already be run. On Windows, the following command will run Node.js, execute app.js in the application and start listening on local port 3000:

SET DEBUG=oraclejetwithnodejs:* & npm start

(alternatively just node ./bin/www).

Add the Oracle JET Sample application

The Oracle JET Starter Template Quickstart sample application is a client side web application (HTML, JavaScript, CSS and images). It is added to the Node.js application structure mainly as a set of static files that Node.js will serve to the browser requesting these files. The actual JET related work all happens in the browser. It can be a bit confusing to have two kinds of JavaScript files: those that are executed by Node.js and those that are served by Node.js to the browser and that run inside the browser, far away from Node.js.

First, download the Oracle JET Starter Template Quickstart sample application ZIP file from OTN Oracle JET Quick Start application from OTN.

image

Extract the contents into the oraclejetwithnodejs application directory structure, under the public folder in the application scaffold structure.

Here is an overview of the contents of the ZIP file:

image

Move the templates folder under public to the views folder. The resulting directory structure is shown here:

image

As per the instructions in the A-Team article, create a small JavaScript file called partials.js in directory routes.

module.exports = function (basepath) {
return {
process: function (req, res) {
res.sendFile('templates/' + req.params.name, {root: basepath + '/views/'});
}
};
}

This little module takes care of handling requests from the browser for templates. These will be served from the views/templates directory.

Next, make some small modifications in another JavaScript file,  app.js in root of the application.

These two lines – close to the beginning of the file – ensure that the partials module gets loaded into the main application:

var loadPartials = require('./routes/partials.js');
var partials = loadPartials(__dirname);

This line, located after the variable app has been created from module express(), takes care of directing any HTTP request for /templates/some-file-name to the partials module:

// load the templaces using the partials
app.get('/templates/:name', partials.process);

These steps are all it takes to merge the Oracle JET application into the Node.js scaffold application.

Stop the Node.js server if it is still running and start the application locally to verify it is working correctly:

SET DEBUG=oraclejetwithnodejs:* & npm start

image

Prepare the Application for the Application Container Cloud

Not much is needed to prepare this application for deployment on Application Container Cloud (also see this article for an introduction into Node.js application on Application Container Cloud).

We need to create a file called manifest.json that is required by the Application Container Cloud. This file specifies name, version details, a description and most importantly: the operating system command to execute in order to launch the application:

{
"runtime":{
"majorVersion":"0.12"
},
"command": "node ./bin/www",
"release": {},
"notes": "Sample, Quick Start Oracle JET Application prepared to run on Oracle Application Container Cloud"
}

Application Container Cloud also needs the package.json file with Node.js dependencies; this file was created at the time of generating the scaffold application.

Create an application archive (zip file) for the entire oraclejetwithnodejs application.

image

 

Create new Application in Application Container Cloud

From the dashboard of the Application Container Cloud, click on Create Application and choose Node.js application. Provide a name and some details and elect to upload the application archive.

image

Press Create.

The application is uploaded. Then the creation (provisioning) will take place.

After a little while, the application [container]is provisioned and the application is deployed and ready for action:

image

Click on the hyperlink to access the application’s main entry point:

 

image

And here we have the Oracle JET sample application, running from the Oracle Application Container Cloud. By doing just a few small things (add manifest.json with proper start command, create overall application archive, create application on Application Container Cloud  based on archive) – we managed to pull this off.

 

Resources

Download the Oracle JET application, configured for deployment on Application Container Cloud: oraclejetwithnodejs.zip (NOTE: the folder public\js\libs in this zip-file is empty; you need to add the libraries here that Oracle JET makes use of – in my case 37 MB worth of JavaScript libraries).

Oracle JET Home Page

Download Oracle JET Quick Start application from OTN

An article from the Oracle A-Team on how to run a sample Oracle JET application on a Node.js server: http://www.ateam-oracle.com/oracle-jet-with-nodejs/

Share this on .. Tweet about this on TwitterShare on LinkedInShare on FacebookShare on Google+Email this to someoneShare on TumblrBuffer this page

The post Deploying an Oracle JET application to Application Container Cloud and running on Node.js appeared first on AMIS Oracle and Java Blog.


Viewing all articles
Browse latest Browse all 163

Trending Articles