SparkFun Inventor's Kit for Edison Experiment Guide
Appendix B: Programming Without the XDK
The Intel® XDK offers some really useful features when programming, such code completion, automatic installation of libraries, and formatting new projects (e.g. templates). However, we totally understand if you don’t want to use the XDK. The good news is that the Edison is a full computer, which means it is more than capable of installing libraries and running code on its own!
There are several ways to write code. Finding a good editor can be a challenge. If you fancy yourself an old-school Unix guru, you might be comfortable with vi. All you need to do is log in to the Edison through SSH or serial and enter the command
You will be greeted with the perhaps familiar vi interface.
If you dislike vi but still want to edit code on the Edison directly, you could install another editor. For example, nano has been added to the Edison’s package repositories. See here to install nano.
XDK offers the benefit of editing code on your computer (desktop or laptop) and the ability to send that code directly to the Edison. You can use any number of editors on your personal computer for editing code. For example, Notepad++ for Windows, TextWrangler for Mac, or Emacs for Linux.
Once you are done writing the code, you can send it to the Edison through a number of ways:
- Copy and paste the code into vi on the Edison and save it
- Use scp (Linux/Mac) or WinSCP (Windows) to transfer the file(s) from your computer to the Edison
- Upload the code as part of a GitHub repository and download it on the Edison
into the SSH or serial terminal of the Edison.
Save it as test.js in the home directory on the Edison (/home/root). Log into the Edison and make sure we are in the home directory.
Then, run the program.
You should see a few messages printed to the console.
Installing Node Modules
npm install <module name>@<version number>
For example, to install the version of Socket.IO as required by Experiment 5, Part 2, enter the following command into the Edison console:
npm install email@example.com
Note that this requires the Edison to be connected to the Internet, as it will attempt to find and install Socket.IO v1.3.7 from the npm package repository.
You do not need to create a package.json file (like we did with the XDK) to accompany your code. The
npm install command installs the package directly on the Edison. As long as your code as the necessary
require('socket.io') line, you will be able to use Socket.IO.
A list of available modules can be found on npmjs.com.