The goal of this project is to create a Scratch project that connects to a self-hosted or remote server in order to update the unread message count of the current user of that project. To do this, you need a computer or Raspberry Pi, a Scratch account that is not a New Scratcher, Node.js, and NPM.
Begin by opening the existing Scratch project. Then click the Remix button in the top blue bar.
If you aren't already on the machine that will be your server, switch over now. I highly recommend that you use a Linux-based operating system (Raspberry Pi OS, Ubuntu, Fedora, etc), but Windows will work if it has to. You'll need to set what are called environment variables. There's a tutorial for Linux OS's here and Windows 10 here. Note that you'll have to be on an admin account to change these. Here are the vars to set and their values (no need for quotes or anything):
SCRATCH_USERNAME
: your Scratch usernameSCRATCH_PASSWORD
: your Scratch passwordMESSAGECOUNTID
: the project ID of the saved Scratch project you remixed earlier (that's the long number at the end of the URL)
If you already have Git, then you probably know how to clone
this project to your PC. If you don't just download this and this by pressing Ctrl
+ S
. Make sure to put them in a new folder.
Here's where NPM comes in. Open a new terminal or command prompt and use basic commands to move into the folder where you downloaded those files earlier. Then run npm install
to automatically install everything the code needs to run.
To start the server, simply type node server.js
! Every time you click the green flag, the message count will update. You can also change the Update
variable's value if you want to force an update.
If you want to run the server in the background without constantly having a terminal window open, install PM2 (which stands for Process Manager 2):
npm install -g pm2
Then move into the directory where the server code is and run pm2 start server.js
. You can also use pm2 save && pm2 startup
to start the server after your computer boots up.