Easiest & fastest recipe to run “.js” sketches under p5.js:
- Install any Firefox-based browser in your OS and use it to open your “index.html” file:
- Install Notepad2 or Notepad++ (or both) in your OS and use it to type in your “sketch.js” file there:
- You can setup those text editors to use UTF-8 and LF line endings for better compatibility.
- Here’s my minimum “index.html” template file which can run most “sketch.js” files out there:
<!DOCTYPE html>
<meta charset=utf-8>
<meta name=viewport content=width=device-width,initial-scale=1>
<script defer src=https://cdn.JsDelivr.net/npm/p5></script>
<script defer src=https://cdn.JsDelivr.net/npm/p5/lib/addons/p5.dom.min.js></script>
<script defer src=sketch.js></script>
- Now you can create a folder and place both “index.html” & “sketch.js” files inside it.
- W/ Firefox opened, drag & drop the “index.html” file into it.
- It should automatically run your “sketch.js” code there.
- Otherwise, if there’s anything wrong in your code, hit the F12 key or the key combo CTRL + SHIFT + J in order to open the browser’s console, and check for any error messages there.
Here’s some p5.js sketch running online w/ both “index.html” über minimum file & the “sketch.js” code file: