Using node modules with p5.js?

edited February 2018 in p5.js

I'm trying to save an object in a json file and I want to use the fs node module to do this. How am I supposed to use node modules with p5.js? It keeps returning 'require is not defined'.

Tagged:

Answers

  • You have two issues here:

    1. require() isn't a standard JS method and isn't provided by p5. You can solve that by using a library like Browserify, or the Webpack build tool, but that's not entirely trivial and it won't solve...
    2. fs is a server-side node module and won't run in the browser.

    It is however possible to prompt the user to save a file with saveJSON

Sign In or Register to comment.