var express = require('express');
var router = express.Router();
var FirebaseAccount = require('firebase-admin');
var Firebase = require('firebase');
var fbInfo = {email: process.env.PYRO_INFO_EMAIL, password: process.env.PYRO_INFO_PASS};
/* GET home page. */
router.get('/', function(req, res) {
  res.render('index', { title: 'Express' });
});
router.post('/create', function(req, res){
	console.log('request received:', req.body);
	if(req.body.hasOwnProperty('name')){
		console.log('request has name param:', req.body.name);
		FirebaseAccount.getToken(fbInfo.email, fbInfo.password).then(function(token) {
		  var account = new FirebaseAccount(token);
		  var dbName = 'pyro-'+ req.body.name
		  account.createDatabase(dbName)
		  .then(function(instance) {
		    var fb = new Firebase(instance.toString());
		    console.log('instance created:', instance.toString());
		    // [TODO] Save new instance to pyro firebase
		    res.writeHead(201, {'Content-Type':'text/plain'});
				res.write(instance.toString());
			  res.end();
		  }).catch(function(err) {
		    console.error('Oops, error creating instance:', err);
		    res.writeHead(500, {'Content-Type':'text/plain'});
				res.write(err.toString());
				res.end();
		  });
		})
	} else {
		res.writeHead(500, {'Content-Type':'application/json'});
		res.write('Incorrect request format');
		res.end();
	}

});

module.exports = router;

@@ -465,16 +465,50 @@
 ame'))%7B%0A
+%09%09var newAppName = req.body.name;%0A
 %09%09consol
@@ -540,26 +540,23 @@
 aram:', 
-req.body.n
+newAppN
 ame);%0A%09%09
@@ -796,16 +796,19 @@
     var 
+app
 fb = new
@@ -835,24 +835,88 @@
 oString());%0A
+%09%09    var pyrofb = new Firebase(%22https://pyro.firebaseio.com%22);%0A
 %09%09    consol
@@ -1017,24 +1017,186 @@
 ebase%0A%09%09    
+var instanceObj = %7Bname:newAppName, url:instance.toString(), dbName:dbName%7D%0A%09%09    pyrofb.child('instances').child(newAppName).set(instanceObj, function()%7B%0A%09%09    %09
 res.writeHea
@@ -1230,32 +1230,33 @@
 t/plain'%7D);%0A%09%09%09%09
+%09
 res.write(instan
@@ -1249,38 +1249,30 @@
 s.write(
-instance.toString()
+newAppName
 );%0A
+%09
 %09%09%09  res
@@ -1275,24 +1275,40 @@
  res.end();%0A
+%09%09    %7D)%0A%09%09    %0A
 %09%09  %7D).catch

Create now includes write to pyro firebase instance list.