Make a directory inside your “tessel-code” folder called “storage”, change directory into that folder, and initialize a tessel project:
mkdir storage; cd storage; t2 init
Plug Tessel into your computer via USB, then plug a USB mass storage device (flash drive) into either of Tessel’s USB ports.
You don’t need to install a library to use a USB storage module. We will use the fs (filesystem) library that’s built into Node.js to interact with USB mass storage devices.
In the folder where you ran t2 init
, rename “index.js” to “storage.js” and replace the file’s contents with the following:
Save the file.
In your command line, t2 run storage.js
Now you can create, write to, read from, and otherwise manipulate files on USB storage devices!
Bonus: Try writing some longer text (or output from a different module) by using streams. Hint: look up the fs function createWriteStream
.
To see what else you can do with a USB storage module, read the fs documentation.
What else can you do with a USB mass storage device? Get inspired by a community-created project.
What are you making? Share your invention!
If you run into any issues you can check out the storage forums.