February 2022: An Unexpected LoJack® Tracker and How to Test Next.js API Routes
I turned the lemons of a stolen car into lemonade, in the form of a new blog post and video on how to build an asset tracker and accompanying dashboard.
Hey friends,
It’s hard to believe we’ve already reached the end of February, and the days are starting to get warmer and longer (although I’m sure we’ll have at least one more good cold snap here before spring takes over and pollen season is upon us).
For me, a few things that have been in the works for a while came to fruition, so I’ve got plenty to share with you whether you like web development, IoT, or even good old-fashioned car chases.
I’ll start off with the most dramatic event: a stolen car and Blues Wireless Notecard in the backseat resulted in Blues TV’s second episode of “The Niedringhaus Effect: Grand Theft Auto Edition”.
Back in November of 2021, while I was home visiting my parents for the Thanksgiving holiday, their car was stolen out of the driveway one night while we were inside eating dinner.
It just so happened I had a Blues Wireless asset tracker in the backseat (I work for the Internet of Things startup Blues Wireless as a software engineer and was building a React-powered dashboard for a side project at the time ), and I was collecting data to use in my dashboard while visiting. And I was able to use my homemade dashboard code to track the vehicle after it was stolen! Later I even shared the dashboard and data with the local police investigating the theft.
While this was a terrible situation to experience firsthand, it gave me quite a story to tell afterwards, and a great real-world use case for the kinds of problems Blues can help solve: namely getting data from the physical world to an accessible cloud in the digital one.
If you’d like to see the whole dramatic story and my blog post showing how to build your own asset tracker from hardware to software for under $100, it’s available now. I’d love to hear about it if you make your own tracker.
Here’s a video of the full dashboard if you’d like to see the finished product.
Continuing the trend of React content, I also wrote a new blog post this month about how to unit test API routes in a Next.js Typescript application.
Next.js is an awesome React-based framework offering all the things a vanilla Create React App starter project does not: server side rendering (SSR), static site generation (SSG), and built-in API routing, to name a few.
One place where the Next.js docs are a bit lacking though, is around how to unit test these built-in API routes, so after I figured out how to do it, I wrote an article to share what I learned with everyone else running into the same roadblock.
With the help of a couple library called node-mocks-http, some test-based environment variables, and a dash of Next.js Typescript types thrown in for good measure, it’s not as complicated as it might seem at first. I hope you find it helpful.
Last but not least, I published a blog about Sequelize, the object relational mapper (ORM) for interacting with SQL databases in JavaScript applications.
Unlike tutorials demonstrating how to use Mongoose to access a MongoDB from a Node.js application, there were very few good examples of how to access a SQL database, so as I built my own user registration application a few years ago, I learned about Sequelize.
It’s the SQL-based equivalent of Mongoose for JavaScript apps, and a pleasure to use for the many flavors of SQL databases out there. Check it out if you’d like a simpler way to interact with databases that involves less standard SQL syntax and more familiar ORM models and commands like findOne
and findAll
.
I hope you enjoyed this month’s edition of “Paige Codes”. Please share with your friends if you did.
See you again at the end of March,
- Paige