node.js


Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
If you want to use JavaScript also on the server side, node.js it the right tool for the job!

After installing node.js you will need some additional Node Packaged Modules
npm install express compression serve-index open
Node Packaged Modules
  • Express
    Sinatra inspired web development framework
  • Open
    open a file or url in the user's preferred application

A list of popular modules can help you to find the right module for the right job.

The source of the server can be found in the openui5-nodeserver GitHub repository
(including the needed package.json).

With the installed base packages a minimal SDK server will look like this:

server.js
var express = require('express'),
    app = express(),
    compression = require('compression'),
    open = require('open'),
    serveIndex = require('serve-index'),
    port = process.env.PORT || 8888,
    publicPath = '/sdk',
    directory = __dirname + publicPath,
    launchUrl = 'http://localhost:' + port + publicPath,
    year = 60 * 60 * 24 * 365 * 1000;
 
// use compress middleware to gzip content
app.use(compression());

// set default mime type to xml for ".library" files
express.static.mime.default_type = "text/xml";

// serve up content directory showing hidden (leading dot) files
app.use(publicPath, express.static(directory, { maxAge: year, hidden: true }));

// enable directory listing
app.use("/", serveIndex(__dirname, {'icons': true}))

// start server
app.listen(port);

// launch uri in default browser
open(launchUrl);

// log to server console
console.log("OpenUI5 SDK server running at\n  => " + launchUrl + " \nCTRL + C to shutdown")


The server can be startet using the command line
node server.js

The "Open" module will automatically start your default browser with the right url.

Now you can start exploring the SDK space inside your browser.

The similar code can be found on a SCN blog post by "John Patterson" called "UI5 SDK on Node.js".

6 comments:

  1. What about connecting sapui5 with mysql using node.js?

    ReplyDelete
  2. Hi Idan, currently this site mostly convers general topics and issues concerning the usage of openui5. We are currently mifaring our SAP E-Commerce B2B suite from Zend/PHP/MySQL to nodejs/mongoDB.

    There are a lot of sites concerning nodejs and database access using restful api or something similar that cover your need and are off topic for this site.

    If we have finished our productive opensource E-Commerce layer, we will add our custom model ui5 model layer so that you can use it also for your custom development with mysql.

    Currently we have to develop a lot of things to be able to do more things with the same comfort we did with Sencha Tools.

    For accessing mySQL i would generate JSON on nodejs serverside an access it with an JSON Model class. After instantiating the model class you are able to load you data using oModel.loadData("uri/myModelData") from a remote destination.

    Hope that helps.

    Holger

    ReplyDelete
    Replies
    1. Thank you i understand better now,
      but my problem is how do I send requests to the node.js serverside from the sapui5 controller?....how does it work? have any specifically good articles or examples about combining the two?

      thanks,
      Idan

      Delete
  3. Have a look at my simple chat sever post that uses nodesjs and web sockets or see the SCN Post http://scn.sap.com/community/developer-center/front-end/blog/2014/01/13/ui5-mobile-splitapp-boilerplate

    ReplyDelete
  4. Hi!

    I just tried to do what is explained in your tutorial. However, there have been some changes in express. They externalized some modules that you'll now need to gather seperately..

    Best Regards,
    Robin

    ReplyDelete
    Replies
    1. Hi Robin
      thanks for the info I have updated the example to the current needs of express. I also put the code to my repository for easy access.

      I am currently spending a lot of time inside SAP Hana so i did not take care of that. I will also write a small blog concerning the new possibilities of the included server task inside the OpenUI5 lib itself.

      You will find this infos inside
      https://github.com/SAP/openui5/blob/master/docs/developing.md

      Cheers Holger

      Delete

Thank you for your comment!

The comment area is not intended to be used for promoting sites!
Please do not use such links or your comment will be deleted.

Holger

Note: Only a member of this blog may post a comment.