Understanding how our node process takes readings

In order to integrate our sensor reading code into our server, first. let's understand what is happening under the hood whenever we execute the node script that takes our sensor readings. Let's review the snippet of code that actually called for the sensor readings:

    /*    Section A    */    sensor.read(11, 4, function(err, temperature, humidity) {        /*        Section B        */        //After reading the sensor, we get the temperature     and humidity readings        if (!err) {            //If there is no error, log the readings to the     console            console.log('temp: ' + temperature.toFixed(1) +     '°C, ' +                'humidity: ' + humidity.toFixed(1) + '%'                )        }    });    /*    Section C    */

Immediately, we can see that the sensor.read method is not synchronous; ...

Get Full Stack Web Development with Raspberry Pi 3 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.