How to get Serial Number of Raspberry pi 3 using NodeJS

Posted By : Chandan Kumar Singh | 10-Jun-2016

How To Get Serial Number of Raspberry Pi 3 Using NodeJS

In this blog we will find the serial number of raspberry pi 3 which is unique. We are going to execute the linux shell command using nodejs. As raspberry pi os which is raspbian  is based on linux kernel so we can run the command supported by debian linux. This code is tested on raspberry pi 3 and node v5.11.1.

Create a file called raspserial.js and copy below code and paste it in the file.

const exec = require( 'child_process' ).exec;
exec('cat /proc/cpuinfo | grep Serial',(error,stdout,stderr) => {
		console.error( `exec error: ${error}` );
	console.log( `stdout: ${stdout}` );// this is your RPI serial number
	console.log( `stderr: ${stderr}` );

Now run the js file

 node raspserial.js

Explanation of code:

first line of code incuding the module of child process, after including we are ruuning the command 'cat /proc/cpuinfo | grep Serial' , the callback function '(error,stdout,stderr)' will contain actual result.

next we are checking if any error has occured then console the error and exit the program, otherwise print the standard output which is the our required Serial number of Raspberry Pi. 


About Author

Author Image
Chandan Kumar Singh

Chandan is a bright Web Developer with expertise in Java and Spring framework and ORM tools Hibernate. He loves technologies like Blockchain and IoT.

Request for Proposal

Name is required

Comment is required

Sending message..