Skip to content

Setup and configure an rpiZero with nodejs, typescript, yarn, pm2, and a test project

Notifications You must be signed in to change notification settings

seadonk/rpiZeroSetup

Repository files navigation

rpiZeroSetup

Setup and configure an rpiZero with nodejs, typescript, yarn, pm2, and a test project

Setup RaspberryPi OS

Raspberry Pi uses an SSD card for all storage. You must place your OS on this card. You can install many OS's but Raspbian is recommended. Since the pi zero is smaller, I recommend the headless version which does not have a Desktop windows-like environment, only terminal.

Setup SSH Access

SSH access is required to use your pi without a monitor, through a terminal.

  • touch ssh

Setup Wifi

create wpa_supplicant.conf and add the text below, so that on reboot, your pi will automatically connect to wifi.

Note, this only works for the Raspberry Pi Zero W model, with built in wifi.

  • nano wpa_supplicant.conf

  • add the following text to the file and save

    country=US
    ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
    update_config=1
    
    network={
    ssid="YOUR_SSID"
    scan_ssid=1
    psk="YOUR_WIFI_PASSWORD"
    }
    
  • Make sure your raspberry pi zero is off

  • Now eject your sd card from your computer, and insert it into your pi zero

  • make sure your raspberry pi is the only one on the network, otherwise it will be named raspberrypi-2 (or whatever #), and you'll have to likely access it by IP address

  • power on your raspberry pi zero

  • wait a minute then try to connect

    • ssh pi@raspberrypi * the password is raspberry
    • you are now in a terminal of your raspberry pi zero!
  • (OPTIONAL) change your password

    • sudo passwd

(OPTIONAL) Setup Passwordless SSH Access using Keys

If you don't do this, then you'll just be prompted for your password everytime you connect

  • on your computer find your key
    • ls ~/.ssh/*.pub
  • if you don't have a key or want a different one generate it
    • ssh-keygen
  • once you have your key, copy it over ssh to your rpi
    • ssh-copy-id pi@raspberrypi then authenticate using your password
  • you should now be able to access your rpi without a password
    • ssh pi@raspberrypi

INSTALL GIT

Recommended for source control, tracking changes in your project, and letting you fetch code from remote repositories like github.com

https://git-scm.com/

sudo apt install git

(OPTIONAL) SSH ACCESS TO GITHUB

SSH access allows you to authenticate using keys instead of passwords.

https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

  • list ssh keys, use an existing public one or create a new one
    • ls ~./ssh/*.pub
  • to generate a key
    • ssh-keygen -t ed25519 -C "your_user_name@github.com"
  • display the key
    • cat ~./ssh/id_ed25519.pub
  • copy the displayed text to the keyboard
  • add the key to your github account ssh keys
  • test your key, you should get a success message
    • ssh git@github

From here you can either run the rest of the steps manually, or clone the repo and run the setup file using sudo sh setup.sh

set timezone

If you want your pi to show you the correct time, you'll have to set the timezone. The time updates automatically with an internet connection.

sudo raspi-config

  • go to localization options > timezone

Update Package List

  • REMOVE Microsoft Crap
    • sudo rm /etc/apt/sources.list.d/vscode.list
    • sudo rm /etc/apt/trusted.gpg.d/microsoft.gpg
  • update system package list
    • sudo apt update
  • (OPTIONAL) update all installed packages (You probably don't need this if your image is recent)
    • sudo apt-get dist-upgrade

INSTALL NODE JS

Node JS will allow you to run javscript (or typescript) code as an alternative to Python.

for rpi zero, use armv61 binaries from nodejs.org

these binaries are no longer officially supported as of node 12+, so you'll have to install node12, or an unnoficial binary

IN the example below we will use the latest unnoficial version

sudo mkdir ~/downloads

cd ~/downloads

(OPTIONAL) INSTALL YARN Package Manager

Yarn is an alternative to NPM

https://yarnpkg.com/

  • npm is bundled with node, use npm to install yarn
  • otherwise apt-get will find the cmdtest yarn package which is different
  • install yarn globally
    • sudo npm install --global yarn
  • verify installation
    • yarn -v

(OPTIONAL) Install Process Manager

This will allow you to automatically start your code on power on, or restart code that exits https://www.npmjs.com/package/pm2

  • install pm2 globally (use npm if you didn't install yarn)
    • sudo yarn global add pm2
  • install typescript for pm2 (#optional if you want pm2 to run typescript files, but not recommended for production)
    • sudo pm2 install typescript
  • verify installation
    • pm2 -v

(OPTIONAL) Install Typescript

If you would like to use typescript instead of plain javascript

sudo yarn global add typescript

sudo yarn global add ts-node

  • Start a repl using ts-node repl

(OPTIONAL) Install GPIO Zero library

This will let you use the pinout command

sudo apt install python3-gpiozero

(OPTIONAL) Install Angular Globally

If you would like to run angular applications.

sudo yarn global add @angular/cli

(OPTIONAL) Clone a test Repo

You can clone the rpiZeroSetup repo to see if your rpiZero is setup correctly.

I recommend putting your repos in a folder like 'projects'

  • mkdir projects
  • cd projects
  • If you setup ssh access to git, you can use the command below
    • git clone git@github.com:seadonk/rpiZeroSetup.git
  • If not, then use this command
    • git clone https://github.com/seadonk/rpiZeroSetup.git
  • cd rpiZeroSetup
  • Install packages
    • yarn install
  • yarn start or npm start if you didn't install yarn
    • You should see test output
  • yarn start-express
    • You should see a url that you can access to find "Hello World"

(OPTIONAL) Create your hello world example

  • In your projects directory, make a new folder:
    • mkdir helloWorld
    • cd helloWorld
  • Create an app.ts file and add some output
    • nano app.ts
    • console.log(`${new Date().toLocaleTimeString('short')} - Hello World!`)
  • Run your app
    • ts-node app.ts
    • You should see your hello world output.

About

Setup and configure an rpiZero with nodejs, typescript, yarn, pm2, and a test project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published