You can use jsdom to simulate a browser environment and initially run Snap.svg in Node.js.
Example:
const jsdom = require('jsdom'); const xmlserializer = require('xmlserializer'); jsdom.env('', [require.resolve('snapsvg')], (error, window) => { if (error) throw error; const paper = window.Snap(100, 100); const rect = paper.rect(20, 20, 60, 60); rect.attr({fill: 'red'}); const svg = xmlserializer.serializeToString(paper.node); window.close(); console.log(svg); });
Print
<svg height="100" version="1.1" width="100" xmlns="http://www.w3.org/2000/svg"><desc>Created with Snap</desc><defs/><rect x="20" y="20" width="60" height="60" style="" fill="#ff0000"/></svg>
source share