cool tech graphics

Running a Persistant Node.js Server on an Arduino Yún

We recently had occasion to set up a Node.js web server on an Arduino Yún. It's a bit more complicated than we thought when we set out, so it seemed useful to share the process. To accomplish this, we need to update the system image, expand the device storage, install node, and launch our server. You'll need a couple things:

Once your supplies are lined up, you can get started with the instructions below. Note: This guide assumes a working knowledge of unix systems, and a basic familiarity with the Yún.

Updating the system image

Copy the system image (download) onto the SD card, then plug it into the Yún. Now log into the Yún’s web admin, and there should be a message indicating that it has found the update, and a button to reset from the image.

Install the update, then get your Yún back on the proper wifi network.

Expanding device storage

Once you're updated to the latest system image (if you do this before updating, your progress will be lost) load the YunDiskSpaceExpander sketch onto the Yún, and connect to the serial console. Follow the on-screen prompts to expand your partition. When it asks you for a partition size, Make sure it's at least 1GB, so there's enough room for your software updates, and a swapfile.

Installing Node

After expanding your device storage, ssh into your Yún. Once connected, run opkg update then opkg install node. This will install Node.js, and all its dependencies.

Next, install forever. The Yún doesn't have enough memory to install this module on its own, so we need a swap file.

Follow this guide to create one. You can stop at step 5, since the Yún wipes out your fstab on every reboot anyway (a problem for another blog post). Once you've finished Step 5, verify you have swap space with free -m

Once your swap is set up, install the module with npm install forever -g. Finally, launch the server with forever start server.js. If everything went according to plan, you should now be able to access your server persistently. Finally, you can run swapoff [swapfile] and rm [swapfile] to reclaim your disk space.

Date posted: January 15, 2015


Excellent article, thank you! This was very helpful for me in getting Node running permanently on my Yun.

I found the following warning during installation:
npm WARN optional dep failed, continuing fsevents@1.1.1
But the installation seems to be properly completed......
Moreover, when I try to launch the server with:
forever start server.js
I have the following errors:
info: Forever processing file: server.js
error: Cannot start forever
error: script server.js does not exist.
What could be the problem ?
Thankyou very much for your help

Thank you so much for this guide. I am replacing an older yun running a persistent nodejs server, but for some reason i can't use npm after expanding the disk space, creating a swapfile, and installing node. Is there anything else I should try in order to troubleshoot or an alternative way to install forever?

$ opkg install node
Package node (v6.11.2-4) installed in root is up to date.
$ free -m
total used free shared buffers cached
Mem: 59932 41732 18200 648 13020 10900
-/+ buffers/cache: 17812 42120
Swap: 65532 444 65088
$ npm install forever -g
-ash: npm: not found

UPDATE: looks like you need to install node-npm separately with opkg:
$ opkg install node-npm

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <cpp>, <java>, <php>. The supported tag styles are: <foo>, [foo].
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.

Metal Toad is an Advanced AWS Consulting Partner. Learn more about our AWS Managed Services

Have questions?