Install Node SerialPort on Raspberry Pi

Since I had a lot of trouble installing the npm package serialport on my Raspberry Pi B Rev 1 (and Rev 3), I want to share how it eventually worked.

When installing serialport I ran into a lot of errors.
When trying to install using npm install serialport you might see those errors.

Enable serial port usage by adding  enable_uart=1 to the file /boot/config.txt.

If the normal  npm install serialport doesn’t work for you try the following.

Install Node 6.x

curl -sL | sudo -E bash -
sudo apt-get install -y nodejs 
sudo apt-get install -y build-essential

Install node-gyp and node-pre-gyp globally

sudo npm install -g node-gyp
sudo npm install -g node-pre-gyp
sudo npm install serialport --unsafe-perm

Open a terminal to the folder  node_modules/serialport and build the downloaded serialport module with the command  sudo node-gyp configure build.

Serialport build success
“gyp info ok” tells you that it worked!

Run a test script (source) to see whether the installation was successful.

var SerialPort = require('serialport');
var port = new SerialPort('/dev/tty-usbserial1');
port.on('open', function() {
  port.write('main screen turn on', function(err) {
    if (err) {
      return console.log('Error on write: ', err.message);
    console.log('message written');
// open errors will be emitted as an error event 
port.on('error', function(err) {
  console.log('Error: ', err.message);

Published by

Timo Denk

Software developer at SAP and Denk Development, student of Applied Computer Science at Baden-Württemberg Cooperative State University. Interested in programming, math, microcontrollers, and sports.

4 thoughts on “Install Node SerialPort on Raspberry Pi”

  1. Hi Timo denk

    I try install serialport in my rpi2 but it not work. I do it all steps that you show in this article but always fail the instalation

    I am using nodejs v6.10.2 and npm 3.10.10

    Do you have a sugerences? I need help.

  2. Hi Timo Denk

    i try install serial port in my rpi3 , but
    npm WARN enoent ENOENT: no such file or directory, open ‘/home/pi/package.json’
    npm WARN pi No description
    npm WARN pi No repository field.
    npm WARN pi No README data
    npm WARN pi No license field.

    How to solve this problem? i need your help


Leave a Reply

Your email address will not be published. Required fields are marked *