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:

  1. you can work well offline
  2. you can be sure to have your work saved locally
  3. you don't have to see the editor
  4. it should run at least a little faster since you don't need to wait for communication with the editor's server
  5. 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:

  1. install nodejs and npm
  2. using npm, install http-server
  3. make a directory for your project
  4. put the necessary files in the directory
  5. run http-server from the command line in that directory
  6. use your browser to access the IP address indicated by http-server

Let's look at each step in detail.

Nodejs is available here, but you probably want to get it from your package manager instead:

https://nodejs.org/en

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:

https://community.chocolatey.org/packages/nodejs.install

NPM, the Node Package Manager, comes with your Nodejs installation. Use it to install the http-server package:

https://www.npmjs.com/package/http-server

  • p5js-local-server.1708489943.txt.gz
  • Last modified: 4 months ago
  • by renick