Get started with Intel NUC and Node.js
In this guide we will build a simple Node.js web server project on an Intel NUC.
Note: The Intel NUC image provides generic x86 device support. While the instructions below refer specifically to the Intel NUC device, you can follow the same steps to provision other devices with an x86 architecture, such as the VIA AMOS-3005 and the Intel Compute Stick STK1A32SC.
At its most basic, the process for deploying code to an Intel NUC consists of two major steps:
- Setting up your Intel NUC with balenaOS, the host OS that manages communication with balena 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 application.
Once these steps are finished, your Intel NUC will download the container image, kick off your application, and begin sending logs to your balena dashboard!
What you will need
- An Intel NUC mini PC from Intel.
- A 4GB or larger USB thumb drive.
- A HDMI enabled LCD screen and HDMI cable.
- A simple USB keyboard.
- A power supply unit for the NUC.
- An ethernet cable or WiFi adapter to connect your device to the internet.
- A balena account.
If you don't already have a balena account, make sure to sign up before continuing.
Create an application
An application 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 application, but can be migrated to another application at any time.
To create your first application, log into your balenaCloud dashboard and click the Create application button.
Select the Intel NUC device type, choose an application type, enter a name, and click Create new application:
Note: To create an application with multiple containers, you'll want to use the starter or microservices application type. The starter applications are full-featured and free for all users, with a limit of up to 10 total devices across all starter applications.
After the application has been created, you will be redirected to the dashboard for the newly created application, where you can add your first Intel NUC.
Add your first device
To connect with balena, your Intel NUC needs a balenaOS image configured for your device type, application, and network. Start by clicking Add device in your application dashboard:
For most applications, you will have the option to select a device type. By default, the device type you chose when you first created the application will be selected. Applications can, however, support any devices that share the same architecture, so you can choose another device type if needed.
After selecting a device type, 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 can be found 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 and the option to download just a configuration file (
config.json) rather than an entire image:
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
FirstApp is the name you gave your application on the dashboard.
The next step is to flash the downloaded image onto your USB drive using Etcher, a simple, cross-platform USB drive writer and validator. Once you have Etcher installed, start it up. To give Etcher access to your USB drive, your system may prompt you to grant administrative privileges.
To create a bootable balenaOS USB drive, follow these steps:
- Click Select image and find your application's balenaOS image file.
- If you haven't already done so, insert your USB drive into your computer. Etcher will automatically detect it. If you have more than one USB drive inserted, you will need to select the appropriate one.
- Click the Flash! button.
Etcher will prepare a bootable USB drive and validate that it was flashed correctly. This can take roughly 3 or more minutes, depending on the quality of your USB drive. You'll receive a notification when it completes, and Etcher will safely eject the USB drive for you.
Note: You can burn several USB drives with the same image file, and all the devices will boot and provision into your application's fleet. You can also disable the auto-ejecting or validation steps from the Etcher settings panel.
Put the USB drive into your device and connect either the ethernet cable or WiFi adapter. Ensure that the HDMI screen and keyboard are connected up.
Warning: BalenaOS will completely overwrite the internal media of your NUC, so if you have important data on the device, we recommend that you make a backup before you attempt provisioning the NUC on balena.
Now connect up the power supply and turn the device on by pushing the small round button on the top of the device.
Press the F10 key while the BIOS is loading in order to enter the boot menu. Next, select the
UEFI : USB option from the boot menu so that the device will boot from your USB drive.
Once the device boots, you should see it pop up on your balena dashboard. It will immediately go into a
flashing internal media state. This means that the device is flashing the balenaOS onto your internal flash media.
After a few minutes, the OS will be fully flashed to the internal media and the device will shut itself down. At this point, you will see on the dashboard that the device is in a
Post-provisioning state. You can now remove the USB drive and press the power button once again.
Your NUC should now automatically boot into the balena OS and you should see the device online and in an
Idle state on your dashboard, ready and waiting for some code to be deployed.
Note: If for some reason your device does not boot into balenaOS, you may need to go back into the BIOS and make sure the boot order correctly selects to boot from the internal SATA drive and not from USB.
Now that we have a device or two connected to a balena application, let's deploy some code and actually build something.
The recommended way to deploy code is to install the balenaCLI. The easiest way to do this is to use the installer for your OS available on the releases page. Choose the latest release of the installer for your OS, and follow the installation instructions.
Note: You may also install the balenaCLI via npm on a system running NodeJS, as explained in NPM Installation.
To use the balenaCLI, you need to login to your balena account. Login via the terminal using the
balena login command:
$ 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 how you wish to authenticate. The recommended method is that of Web authorization, which will bring up a browser window (and prompt you to first login to balena if you have not) and ask for confirmation that you wish to authorize the CLI. Click Authorize and head back to your 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 balenaCLI by running the
balena apps command, which should return information about the application you created in the previous step. Take a note of the
APP NAME as you'll need this in the next step to push the code to all devices in that application.
$ balena apps ID APP NAME DEVICE TYPE ONLINE DEVICES DEVICE COUNT 98264 FirstApp raspberrypi4-64 0 0
Note See all the commands available with balenaCLI by running
A nice first project to get started is a simple Express.js web server which, will serve a static page on port
:80. All the project source code can be found here on GitHub. Download a zipped file of the project here, and when downloaded unzip the file and navigate to the directory of the project e.g.
$ cd simple-server-node-master
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 application, use the
balena push FirstApp command replacing
FirstApp with the name of your application. Ensure you are in the root of the project directory before issuing this command.
$ balena push FirstApp
This command will package up and push the code from the local directory to the balena builders, where it will be compiled and built and deployed to every device in the application 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 [Info] Built on arm02 [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 application will then be downloaded and executed by all the devices you have connected in your application 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 in the Applications dashboard.
If you follow the URL, you will be served a page with some additional balena learning resources and next steps. Alternatively, you can point your browser to your device's IP address.
- Try out local mode, which allows you to build and sync code to your device locally for rapid development.
- Develop an application with multiple containers to provide a more modular approach to application management.
- Manage your device fleet with the use of configuration, environment, and service variables.
- Explore these example projects to give you an idea of more things you can do with balena.
- If you find yourself stuck or confused, help is just a click away.
Enjoy Balenafying All the Things!