# MarkLogic-Node Generator

This application was generated by the MarkLogic-Node [Slush](https://github.com/klei/slush) generator, with the following components:

- [AngularJS](https://angularjs.org/)
- [Gulp](http://gulpjs.com/)
- [node.js](http://nodejs.org/): very thin layer, hosting the Angular code and proxying MarkLogic REST API requests
- [Roxy Deployer](https://github.com/marklogic/roxy): bootstrap MarkLogic databases, application servers, etc; scaffolding for MarkLogic REST API service extensions

## Install Required Dependencies

- [node.js](http://nodejs.org/download/)
- [npm](https://www.npmjs.com/): Built-in package manager for node (comes with
  node, but check to be sure you have latest version: `npm install -g npm`)
- [gulp](http://gulpjs.com/): Javascript task automation (`npm install -g
  gulp`)
- [Bower](http://bower.io/): A package manager for front-end libraries (`npm
  install -g bower`)
- [Git](https://git-scm.com/) - Roxy depends on this version control system
- [Ruby](https://www.ruby-lang.org/en/documentation/installation/) - Roxy
  depends on Ruby in order to run server configuration scripts

# Running the application

    ./ml local bootstrap
    ./ml local deploy modules

On Windows, that would be:

    ml.bat local bootstrap
    ml.bat local deploy modules

Install additional dependencies using the bower package manager:

    bower install

If you want to upload a dictionary for spell-suggestions:

    ./ml local deploy content

On Windows:

    ml.bat local deploy content

Edit `./local.json` to set your desired ports

    gulp serve-local # this will watch the .less file for changes, compile them to .css, and run the node server

# Installing as service

The code includes a service script, and a service config to make installing express server service as easy as possible. The following files are involved:

- etc/init.d/node-express-service (generic express server service script)
- etc/{app}/conf.sh (application specific service configuration, any application name allowed)
- boot.js (entry point for express service, calls out to server.js)
- node-app.js (required by boot.js)

The conf.sh is 'sourced' by the service script, and allows overriding the built-in defaults. Usually you only need to override SOURCE\_DIR, APP\_PORT, and ML\_PORT. Make sure they match the appropriate environment.

Next install [forever](https://www.npmjs.com/package/forever) globally if it is not already installed.

- `$ [sudo] npm install forever -g`

Next, push all source files to the appropriate server. The following assumes it was dropped under /space/projects/ in a folder called slush-app.live. Take these steps to install the services:

- cd /space/projects/slush-app.live
- gulp build # this will create the ./dist/ folder with all the required assests and code
- cd /etc
- sudo ln -s /space/projects/slush-app.live/etc/{env} slush-app
- cd /etc/init.d
- sudo ln -s /space/projects/slush-app.live/etc/init.d/node-express-service slush-app
- sudo chkconfig --add slush-app
- sudo chkconfig --levels 2345 slush-app on

Next to start it, use the following commands (from any directory):

- sudo service slush-app start

These services will also print usage without param, but they support info, restart, start, status, and stop. The info param is very useful to check the settings.

# Data

## Sample Data

The application comes with 3000 JSON documents generated by json-generator.com.
You can load them with
(MLCP)[https://docs.marklogic.com/guide/ingestion/content-pump] like this:

    ./ml local mlcp -options_file import-sample-data.options

Or on Windows:

    ml.bat local mlcp -options_file import-sample-data.options

## General Data Information

The application assumes that you're storing JSON data. This shows up in the
default format request for the MLRest service's `searchContext`, the
`detailController`'s (`detail-ctrl.js`) request to get a document, and in the
out-of-the-box detail view.
