The code
Let's write the code to bring our surveillance system to life.
The setup requires Node.js to be installed on Raspberry Pi which we have already done quite a few times through out this book so we will not repeat that and straightaway start writing the code.
Camera module code
To use the camera, we need to include a library from npm
. We use the pi-camera library, and to install it, run the command in the terminal, as shown in Figure 6.23. Check out the official link for the pi-camera npm
module at https://www.npmjs.com/package/pi-camera:

Figure 6.23
Now, create a file with the name CameraModule.js
and include the pi-camera
module in it:
const PiCamera = require('pi-camera');
As per the documentation of the pi-camera
module, we need to set the configuration of the camera. We define both configurations, one for taking still pictures and the other for taking videos:
const myCameraPhoto = new PiCamera({ mode: 'photo', output: `/home/pi/Node_Programs/photos/photo.jpg`, width: 640, ...