Skip to content

Optional: Cloud9 Development Environment

Chris Beam edited this page Apr 1, 2016 · 6 revisions

Create your account

Make your free account with Cloud9 here. I found the easiest way to make a new account is to use the GitHub Account Creation tool found at the top of the page.

Setup your workspace

  1. Name and describe your new workspace
  2. Fork HospitalRun to your own repository in GitHub or elsewhere
  3. Clone HospitalRun from your own repository using the Clone from Git field
  4. Select Node.js from the Choose a template field to finish setting up your workspace

Screenshot of Cloud9 Setup Page

One of the awesome things about Cloud9 is that many of the dev tools you want are preinstalled, like CouchDB. All you need to do is get Couch running. Run the following commands to get CouchDB setup in Cloud9:

sudo mkdir -p /var/run/couchdb
sudo chown couchdb:couchdb /var/run/couchdb 

Install Packages and Dependencies

From ~/workspace, run the following commands to update and install additional software:

npm install -g npm               #optional
npm cache clean -f               #optional
npm install -g n                 #optional
sudo n stable                    #optional
npm install -g ember-cli@latest
npm install -g bower
npm install
bower install
npm install -g phantomjs-prebuilt

Run CouchDB

To run CouchDB, use the following command: sudo su couchdb -c /usr/bin/couchdb. To test if CouchDB is running, run curl http://127.0.0.1:5984. Use the sudo command every time you launch CouchDB, or the Ember app will fail to load.

Config CouchDB for HospitalRun testing

Make sure CouchDB is running (see below), then run the following script from ~/workspace: ./script/initcouch.sh. When the script terminates, run cp ./server/config-example.js ./server/config.js

Start Ember app

The easiest way to start the Ember app is to run npm start from the root of your workspace. If this fails to work, check the error log that prints out. ember s (or ember serve) is another way to start the HospitalRun localhost server.

Update dependencies

Each time you work on this project, you're probably going to want to update your fork from HospitalRun's master. To do this, you need to set up HospitalRun as the upstream repository to your personal origin repo. Use this guide from GitHub for help on using forks correctly.
For your dependencies to work properly, they will need to be updated every time the package information is changed. To update them, run npm install and bower install from the root of your workspace.

Access to Futon through Cloud 9

Since Cloud9 only opens ports 8080, 8081, and 8082, you'll need a work around to view the GUI for CouchDB. Save the following code as /home/ubuntu/workspace/c9-couch.js:

var http = require('http');
function onRequest(req,res) {
    var postData = '';
    req.addListener("data", function(postDataChunk) {
        postData += postDataChunk;
    });
    req.addListener("end", function() {
        makeCouchRequest(req.url, req.method, postData, function(cdata, ct) {
            res.writeHead(200, {
                'Content-Type': ct
            });
            res.end(cdata);
        });
    });        
};
function makeCouchRequest(url,method,data, cb){
    var req = http.request({
        host: process.env.COUCHIP || "127.0.0.1",
        port: process.env.COUCHPORT || 5984,
        path: url,
        method: method
    },function(response){
        var str='';
        response.on('data', function(chunk){
            str += chunk;
        });
        response.on('end', function(){
            cb(str,response.headers['content-type']);
        });
        
    });
    req.write(data);
    req.end();
};
var server = http.createServer(onRequest); console.log('c9couch server created'); server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function(){
  var addr = server.address();
  console.log("c9couch server listening at", addr.address + ":" + addr.port);
});

To access this webpage, make sure couchdb is running (see above) and run node c9-couch.js. Then navigate to the page by going to https://-.c9users.io/_utils/ but do not forget to end the address with a slash!