Raspberry Pi File Upload

I was looking to create a simple Upload application for the Raspberry pi. I am a fan of IOT, and I am currently a computer science student. The raspberry pi zero, and pi 1 have different processors than the raspberry pi 2 and pi 3. (ARM6 vs ARM7).

First:

I needed a way for this "web application" to run on any version of raspberry pi. I decided to use NodeJs for various reasons. Node can be run on multiple threads with pm2, NodeJs is faster than php, and NodeJs is the fastest growing language of all time. Raspbian OS has node already installed when you flash the image to your pi. However, it is not the most current version of NodeJS, so here is a shell script I made to install the latest version of Node. I made the script as easy as: copy/paste the README.md code block into your pi terminal: NodeJs-Raspberry-Pi

Second:

  • (Libraries)

If you are new to node, then get ready for a wild ride, and I don't mean a bad ride. Node has many different ways you can start a web server:

  1. You can run your web server from the HTTP library (i don't exactly recommend this).
  2. You can use the Express Library.
  3. You can use the Hapi.js Library.
  4. You can find another library.
    • The best way to find libraries is to visit npm and search for something you find interesting.
    • You will eventually use npm to build your application from other people's built modules.
    • I highly recommend that if you are fairly new to node that you build simple applications by combining two different modules that already exist.
    • When designing an application it also helps to watch others code. My favorite youtube channel is here, which I watch every week on Monday. Check out higher order functions, maps, and reduce

Once I decided to use Express, it was just a matter of finding libraries that suited the needs of uploading a file to the raspberry pi's file system. I decided on: multer.

Third:

  • (Code)

I found that the best browser tabs to have open while building NodeJs applications is the:

and also these, because I used them the most:

I was so happy that I found myself not using for loops because I could use functors (functions that take another function as a parameter). Functors are a unique essence of NodeJs and JavaScript that most languages don't offer in the same way JavaScript does. The reason node is so damn fast is summed up quite well by Ryan Dahl: The original mastermind behind NodeJs.

Last:

  • (publishing)

I contacted lifeHacker.com because all the coder kids hang out there. They publish the Instructables the next day, and Dataplicity published the project on their announcement page a day or two after lifeHacker. I can't stop learning NodeJs. It's so powerful, and there are so many wonderful application that are being built at an amazing pace. What seperates NodeJs from the rest is not only is it fast, but your dependencies are installed recursively. So when you install a dependency, if that dependency has dependencies, then your node package manager (npm) will install those dependencies, and if those dependencies have dependencies then they will be installed also, and etc...


Here are the links to the project and publication: GitHub, lifeHacker, Dataplicity, and Instructables