How to export by *.bpmn format

I can import BPMN 2.0 xml file with this code :

var BpmnViewer = require('bpmn-js');

var xml; // my BPMN 2.0 xml
var viewer = new BpmnViewer({ container: 'body' });

viewer.importXML(xml, function(err) {

  if (err) {
    console.log('error rendering', err);
  } else {

but I dont know how to export with xml format from bpmn project like press download bpmn button

First Of All You should Use “modeler” instead of “viewer”. After that use the following code

modeler.saveXML({ format: true }, function (err, xml) {
  // here xml is the bpmn format