Get started with UP Board and Node.js
In this guide, we will build a simple Node.js web server project on a UP Board. At its most basic, the process for deploying code to a UP Board consists of two major steps:
- Setting up your UP Board with balenaOS, the host OS that manages communication with balenaCloud and runs the core device operations.
- Pushing your Node.js project to the balena image builder, which pulls in all necessary dependencies and creates the container image for your fleet.
Once you complete these steps, your UP Board will download the container image, start your application, and begin sending logs to your balena dashboard!
What you will need
- An UP board, UP squared, or UP core. See our supported devices list for other supported boards.
- A 4GB or larger USB key.
- An ethernet cable or WiFi adapter. Check our list of supported WiFi adapters.
- A 5V @4A UPboard power supply.
- A USB keyboard.
- An HDMI LCD screen.
- A balena account.
If you don't already have a balena account, make sure to sign up before continuing.
Create a fleet
A fleet is a group of devices that share the same architecture and run the same code. When you provision a device, it is added to a specific fleet, but can be migrated to another fleet at any time.
To create your first fleet, log into your balenaCloud dashboard and click the Create fleet button.
Select the UP Board device type, choose a fleet type, enter a name, and click Create new fleet:
Note: To create a fleet with multiple containers, you'll want to use the Starter or Microservices fleet type. The Starter fleets are full-featured and free for all users, with a limit of up to 10 total devices across all Starter fleets.
After the fleet has been created, you will be redirected to the dashboard for the newly created fleet, where you can add your first UP Board.
Add your first device
To connect with balenaCloud, your UP Board needs a balenaOS image configured for your device type, fleet, and network. Start by clicking Add device in your fleet dashboard:
For most fleets, you will have the option to select a device type. By default, the device type you chose when you first created the fleet will be selected. Fleets can, however, support any devices that share the same architecture, so you can choose another device type if needed.
After selecting a device type, select an OS type of balenaOS, and you will see a list of available balenaOS versions. In general, you should use the most recent version available. You can also select whether to use a Development or Production edition with the respective toggle:
Note: When you're getting started, a Development image is the most useful, as it permits many testing and troubleshooting features. For production use, be sure to switch to a Production image. More details on the differences between Development and Production images are detailed here.
A toggle is also used to select whether your network connection will be through Ethernet Only or with the option for Wifi + Ethernet. Selecting Wifi + Ethernet allows you to enter a Wifi SSID and Wifi Passphrase:
Clicking Advanced presents the option to select the rate at which your device checks for updates:
Once you have finished your image configuration, click the Download balenaOS button. When the download completes, you should have a zipped image file with a name like
First-Fleet is the name you gave your fleet on the dashboard.
Alternatively, by clicking on the toggle section of the download button, you also have the option to download just a configuration file (
config.json) rather than an entire image.
The next step is to flash the downloaded image onto your USB key using Etcher, a simple, cross-platform USB key writer and validator. Once you have Etcher installed, start it up. To give Etcher access to your USB key, your system may prompt you to grant administrative privileges.
To create a bootable balenaOS USB key, follow these steps:
- Click Select image and find your fleet's balenaOS image file.
- If you haven't already done so, insert your USB key into your computer. Etcher will automatically detect it. If you have more than one USB key inserted, you will need to select the appropriate one.
- Click the Flash! button.
Etcher will prepare a bootable USB key and validate that it was flashed correctly. This can take roughly 3 or more minutes, depending on the quality of your USB key. You'll receive a notification when it completes, and Etcher will safely eject the USB key for you.
Note: You can burn several USB keys with the same image file, and all the devices will boot and provision into your fleet. You can also disable the auto-ejecting or validation steps from the Etcher settings panel.
In order to get balenaOS up and running on your UP Board, you need to first set it up to boot from your USB key rather than its internal eMMC memory. To do this, you will need to interrupt the boot process and direct the device to boot from your USB key.
Note: BalenaOS will completely write over the existing eMMC.
First, make sure the device is setup correctly:
- Ensure you have a HDMI screen attached and powered up.
- Make sure the USB key is plugged into one of the 4 available USB ports.
- Attach a USB keyboard to one of the other available USB ports.
- Attach a USB WiFi dongle or an ethernet cable to give the device access to the internet.
Now that you have your board setup, apply power to it using the supplied 5 Vdc barrel jack. Tap the
F7 key while the BIOS is loading in order to enter the device's boot menu. If all goes according to plan, you should see the boot menu as pictured below:
Using the keyboard arrow keys, select the
UEFI : USB option and hit enter. Your UP Board will now boot from the USB key and flash balenaOS onto the internal eMMC memory. If your device is correctly connected to the internet, you should see progress of the flashing on your balena dashboard. Once balenaOS is safely flashed onto the internal eMMC memory, the device will shut itself down and you should see all the user LEDs on the board switch off.
Note: The blue power LED will stay illuminated even once the device has shutdown. You can find the user LEDs on the underside of the board near the USB ports.
You can now remove the USB key and power up the board again. Your UP Board should now be sitting happily waiting on the balena dashboard. If it still hasn't appeared after 1 or 2 minutes, double check your ethernet connection or that you entered the right WiFi credentials at download time. If you still can't get it online, contact us on support.
Now it's time to deploy some code!
Install the balena CLI
Now that we have a device or two connected to a balena fleet, it's time to deploy some code. We will use the balena CLI for this. Follow the instructions below to install it on your computer (development workstation). Choose the tab for your operating system.
- Download the CLI installer.
- Double click the downloaded file to run the installer and follow the installer's instructions.
- To run balena CLI commands, open a command prompt: Click on the Windows Start Menu, type PowerShell, and then click on Windows PowerShell.
- Download the standalone CLI.
Extract the contents of the zip file to any folder you choose, for example
/home/james. The extracted contents will include a
Add that folder (e.g.
/home/james/balena-cli) to the PATH environment variable. Check this StackOverflow post for instructions. Close and re-open the terminal window so that the changes to PATH can take effect.
For more detailed information, visit the detailed Linux installation instructions.
After the balena CLI is installed, login to your balena account
balena login command on the terminal:
$ balena login _ _ | |__ __ _ | | ____ _ __ __ _ | '_ \ / _` || | / __ \| '_ \ / _` | | |_) | (_) || || ___/| | | || (_) | |_.__/ \__,_||_| \____/|_| |_| \__,_| Logging in to balena-cloud.com ? How would you like to login? (Use arrow keys) ❯ Web authorization (recommended) Credentials Authentication token I don't have a balena account!
You will be asked to choose an authentication method. Choosing Web authorization will bring up a web browser window that allows you to login to your balenaCloud account. When asked to authorize the CLI, click the Authorize button and head back to the terminal.
Note: Other authentication methods include using your username and password credentials or obtaining an authentication token from the dashboard. Authentication tokens come in two types, API tokens, and JSON Web Token (JWT) session tokens. While API tokens do not expire, JWT session tokens do after 7 days.
After logging in, test out the balena CLI by running the
balena fleets command, which should return information about the fleet you created in the previous step. Take note of the
FLEET NAME as you'll need this in the next step to push your code to all devices in that fleet.
$ balena fleets ID FLEET NAME DEVICE TYPE ONLINE DEVICES DEVICE COUNT 98264 First-Fleet UP Board 0 0
Note: See all the commands available with balena CLI by running
A nice first project to get started is balena-node-hello-world, an Express.js web server that serves a static page on port
Note: You may also use git to deploy code to a device. If you wish to deploy via git, see the instructions here.
Now to deploy this code to all device(s) in the fleet, use the
balena push First-Fleet command replacing
First-Fleet with the name of your fleet. Ensure you are in the root of the project directory before issuing this command or specify the
--source option to provide an alternate location of the project directory.
$ balena push First-Fleet
This command will package up and push the code from the local directory to the balena builders, where it will be compiled, built and deployed to every device in the fleet.
You'll know your code has been successfully compiled and built when our friendly unicorn mascot appears in your terminal:
[main] Successfully built d5f1de77fad3 [Info] Uploading images [Success] Successfully uploaded images [Success] Release successfully created! [Info] Release: f4e3925bf7d32226365225e1b7201b90 (id: 89693) [Info] ┌─────────┬────────────┬────────────┐ [Info] │ Service │ Image Size │ Build Time │ [Info] ├─────────┼────────────┼────────────┤ [Info] │ main │ 205.13 MB │ 1 second │ [Info] └─────────┴────────────┴────────────┘ [Info] Build finished in 7 seconds \ \ \\ \\ >\/7 _.-(6' \ (=___._/` \ ) \ | / / | / > / j < _\ _.-' : ``. \ r=._\ `. <`\\_ \ .`-. \ r-7 `-. ._ ' . `\ \`, `-.`7 7) ) \/ \| \' / `-._ || .' \\ ( >\ > ,.-' >.' <.'_.'' <'
Your release will then be downloaded and started by all the devices you have connected in your fleet. The first push is slower to deploy, but all subsequent pushes are much faster due to Docker layer sharing. You can see the progress of the device code updates on the device dashboard:
You should now have a node.js web server running on your device and see some logs on your dashboard.
To give your device a public URL, access the device page, and choose the Public Device URL toggle. You may also activate this for many devices in your fleet at the same time via the Actions menu on the device list within a fleet.
Follow the URL to view a page with additional balena learning resources and next steps. Alternatively, you can point your browser to your device's IP address.
- Head to balenaHub, for more ready-to-deploy fleets, or have a go at building and sharing your own cool projects using balenaBlocks.
- Try out local mode, which allows you to build and sync code to your device locally for rapid development.
- Take a modular approach to application development with multiple containers.
- Manage your device fleet with the use of configuration.
- Pass named values, parameters and data to your application using variables.
- Visit our blog to find step-by-step tutorials for some classic balena projects.
- If you find yourself stuck or confused, help is just a click away.
Enjoy balenafying all the things!