This is an old revision of the document!
hosting your sketches on a local server
We can view our sketches in the p5js editor, or we can host them ourselves with a web server and then open that page with a browser to view it.
What's a web server? It's a software process that can send html and related files using HTTP.
Check out the explanation on Wikipedia: https://en.wikipedia.org/wiki/Web_server
This page describes HTTP: https://en.wikipedia.org/wiki/HTTP
Advantages to doing things this way include:
- you can work well offline
- you can be sure to have your work saved locally
- you don't have to see the editor
- it should run at least a little faster since you don't need to wait for communication with the editor's server
- other advantages…
One of the disadvantages is that you need to set things up, but it's not a lot of work. The steps are as follows:
- install nodejs and npm
- using npm, install http-server
- make a directory for your project
- put the necessary files in the directory
- run http-server from the command line in that directory
- use your browser to access the IP address indicated by http-server
Let's look at each step in detail.
install nodejs and npm
Nodejs is available here, but you probably want to get it from your package manager instead:
For Linux, check your distribution. For example, complete instructions for Arch Linux are here:
https://wiki.archlinux.org/title/Node.js
For Mac, you might use brew:
https://formulae.brew.sh/formula/node
For Windows, you could use Chocolatey:
using npm, install http-server
NPM, the Node Package Manager, comes with your Nodejs installation. Use it to install the http-server package: