Here are the steps to do on the server:
1) Install xmldom
module of node.js:
$ npm install xmldom
2) Clone google's Closure library (github). Be sure the cloned directory is named "closure-library" and is located at the same directory level as your blockly project, like this: (image link)

3) Add a javascript generate.js
in your blockly project folder. Note that here I use blockly xml to generate python code. You need to adjust line 7-10 based on the type of generator you use.
global.DOMParser = require('xmldom').DOMParser;
global.Blockly = require('./blockly_uncompressed.js');
require('./blocks/math.js');
require('./blocks/text.js');
require('./blocks/lists.js');
require('./generators/python.js');
require('./generators/python/math.js');
require('./generators/python/text.js');
require('./generators/python/lists.js');
require('./msg/messages.js');
var fs = require('fs');
var xmlText = process.argv[2];
try {
var xml = Blockly.Xml.textToDom(xmlText);
// Create a headless workspace.
var workspace = new Blockly.Workspace();
Blockly.Xml.domToWorkspace(workspace, xml);
var code = Blockly.Python.workspaceToCode(workspace);
console.log(code);
} catch (e) {
console.log(e);
}
4) Finally, run node.js on generate.js
with your pre-generated XML string:
$ node generate.js '<xml>...</xml>'
Reference:
1) Headless Blockly
2) Blockly code generation on the server side
3) Building Blockly