I recently had to rebuild my laptop and one of the first things I did was to install Node.js and have it statically serve my UI5 SDKs, I thought I would share how easy it is to setup.
"Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications". Node.js has an easy to use command line utility npm for managing the JavaScript dependencies in your applications, npm can also be used for loading one of the many Node.js applications from the npm (Node Packaged Module) registry. Besides using Node.js as an application platform it provides many tools to aid UI5 development, I use node hosted apps inside of Sublime Text for formatting and checking (linting) my code and use gruntjs for automating a lot of the repetitive test, build and deploy tasks, I even use generator-openui5 to create my UI5 mobile projects, views and controllers.
Start at the end
C:\sapui5\sdk is where i store the various UI5 SDK versions, also in that folder i have a JavaScript file static_server.js which has simple code to create a node server and publish the content within the directory
To run the server open up a windows command line window, <shift> <right click> on folder -> "Open command window here" then enter
node static_server
This command starts the server and opens up the default browser with directory listing
from here you can choose to run the SDK
or browse the directory and easily navigate and view the debug files in the browser
The code
static_server.js - put this file in the directory
var express = require('express'), open = require('open'); app = express(), port = process.env.PORT || 8888, sapui5 = '/sapui5' url = 'http://localhost:' + port + sapui5, year = 60 * 60 * 24 * 365 * 1000; // Use compress middleware to gzip content app.use(express.compress()); //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(sapui5,express.static(__dirname, { maxAge: year, hidden: true })); // enable directory listening app.use(sapui5,express.directory(__dirname)); app.listen(port); open(url); //open in default browser console.log("Static file server running at\n => " + url + " \nCTRL + C to shutdown")
In the above code expressjs a lightweight app framework creates compressed and cache-controlled content with directory listing and serves it at http://localhost:<port>/sapui5 , the open module opens the default browser application.
Installation
Installing Nodejs is very simple - goto nodejs.org and click on "Install", the default installation has enough to get started.
Once you have Node.js installed open a command prompt in the directory where the SDK is located, then use npm to install expressjs and node open
this will load the module into the node_modules directory and do the same for open
npm install open
the preferred alternative to manually installing would be to create a package.json
file in the directory and define the dependencies
{ "dependencies" : { "express" : "3.x", "open" : "0.0.x" }
then run "npm install" from the command line.
Once the dependencies are installed you should now be able to run the server
node static_server
Enjoy :-)