# Using p5.js to generate SVG markup from a module

**URL:** <https://discourse.processing.org/t/using-p5-js-to-generate-svg-markup-from-a-module/37360>\
**Category:** Coding Questions\
**Created:** [June 6, 2022, 2:19pm UTC](https://discourse.processing.org/t/using-p5-js-to-generate-svg-markup-from-a-module/37360 "2022-06-06T14:19:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![blundin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/blundin/32/16410_2.png) [@blundin](https://discourse.processing.org/u/blundin)\
**Post date:** [June 6, 2022, 2:19pm UTC](https://discourse.processing.org/t/using-p5-js-to-generate-svg-markup-from-a-module/37360/1 "2022-06-06T14:19:54Z")

</div>

Hello all! I am an experienced web developer who is brand new to p5.js and generative art in general. I’ve spent several hours searching around for an answer to this question, and I suspect I am just thinking about this the wrong way.

I want to use p5.js to generate an SVG image, capture the SVG markup text, and then use that string as a variable a React application.

I’m using p5.js-svg to generate the SVG image, and I’ve been able to capture the SVG markup using getDataURL(). I’d like to be able to wrap this in a module with a function like ‘generateImageMarkup()’, but when I do so I get this error: “ReferenceError: window is not defined”.

It seems like I am trying to force this library to do something it’s not designed to do. What is the right way to approach this problem? What is the p5.js-native approach?

---

<div class="post-metadata">

**Author:** ![mnse](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mnse/32/16520_2.png) [@mnse](https://discourse.processing.org/u/mnse)\
**Post date:** [June 8, 2022, 6:50pm UTC](https://discourse.processing.org/t/using-p5-js-to-generate-svg-markup-from-a-module/37360/2 "2022-06-08T18:50:53Z")

</div>

Hi @blundin,

Maybe the easiest way would be that you setup a sample sketch in [P5js Web Editor](https://editor.p5js.org) on which you try to reproduce this issue than one can have a look…  
Such generic errors can’t be analysed depending on your description above as it can have several reasons why this error is thrown…

Cheers  
— mnse
