My First Node.js Module(s)
Over the past few weeks I have really started to enjoy Node.js.
For those unfamilar, Node.js provides
an asynchronous event driven JavaScript runtime…to build scalable network applications.
What I have really loved while dipping my toe into the water is the simplicity of simple publishing Node.js modules (or packages). To begin learning about Node.js, I decided to write a simple wallpaper changer. This was my reddit-node-wallpaper application. The goal was to create a simple application to:
- Pull posts from reddit,
- Filter by a given criteria,
- Grab the image URL from a random filtered post,
- Download the image, and
- Set the image as the desktop wallpaper.
But if we think about the single responsibility principle, this application does way more than one thing. Working on a new project (use Lorem Picsum to provide the image), I broke the functionality into multiple modules.
- Pull an image from the given URL into memory (image-download),
- Download the image on to the file system,
- Set the image as a wallpaper,
- Orchestrate all the functionality (lorem-picsum-wallpaper – also does the previous 2 functions…), and
- Expose a CLI (lorem-picsum-wallpaper-cli).
This journey to release my first Node.js few modules was an extremely enjoyable experience. I cannot wait to take on larger projects in the future.
For those wanting to get into Node.js, here are a few resources I used:
- Fun Fun Function,
- NodeSchool,
- Eloquent JavaScript,
- Mostly adequate guide to FP (in javascript)
- Sindre Sorhus (bytes of awesome code), and
- jreina/Superlatives