So, I got this all working, including adjusting the speed with PWM. I used a 5V/500mah power supply. So far so good.
For a different iteration of the project, I needed to change the motor out and use this one: https://www.adafruit.com/products/1150. This motor is 12v and uses 200-300ma of current.
A few other components in the project require a lot of power, so my power supply is 12v/5 amps.
Here's the problem. With everything wired exactly as indicated above, it doesn't work very well with the new motor. It's set up so that when I press a button on the Espruino, an LED is lit and the motor is turned on (via PWM on the pin attached to the mosfet's gate). Instead of nice smooth motor power, the motor is very choppy and the LED starts blinking off and on in sync with the motor cutting out. It's almost as if there's not enough power for both the Espruino and the motor. But, the power supply is 5A and I disconnected everything else, so that's ridiculous.
I've tried various PWM duty cycles and frequencies and I can't seem to smooth out the motor.
What am I doing wrong?