I have a dropdown list which contains the name of the branches in a html file. I want to take that name and insert it into below node code so that every single time a user clicks a value in dropdown, it should pass it to node and run the command "git log BRANCHNAME" and store it Json (for now):
var sys = require('sys')
var express = require('express');
var app = express();
app.get('handle', function(request,response,error){
var branchName = request.body.branchname;
console.log("Branch name"+branchName+"");
if(error){
console.log("error");
}
var exec = require('child_process').exec;
var fs = require('fs');
function put(error, stdout, stderr) {
var commitsbybranch = JSON.stringify(stdout.split(/\r?\n/).map(function(e) { return e.substring(0);}).filter(function(e) { return e; }));
fs.writeFile('reacted/testcommitsbybranch.json', commitsbybranch);
}
exec("git log "+branchName+"", put);
console.log("Pulling commits by branch done");
} )
app.listen(3000);
My Jquery code is this so when I click the option I want the value to be passed to above node code
$.getJSON("Branches.json", function (data) {
$.each(data, function (index, item) {
$('#users-dropdown').append(
$('<option></option>').val(item).html(item)
);
});
});
I also need to have proper format of JSON, If I could get help with that too please I need to split each object with right braces.