Accessing the data remotely

In the previous projects of this chapter, we learned how to measure and store data on your Pi. However, in a smart home, the best is to be able to access data remotely, for example, from your smartphone or computer. We will see many similar examples in later chapters of this book, but in this chapter, I just wanted to give you a glimpse of what is possible.

The module we are going to use here is Express, a server framework that is really easy to use with Node.js. Express works by defining routes, which is what will be served to the client if a request is made on a specific URL.

First, we'll import Express and define a main route that will send back the temperature and humidity measurements:

var express = require('express'); ...

Get Building Smart Homes with Raspberry Pi Zero now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.