Skip to content
node.js serial port driver
C++ C JavaScript Other
Branch: master
Clone or download
Latest commit d7d9d61 Jul 22, 2012
Type Name Latest commit message Commit time
Failed to load latest commit information.
bin better close handling Jun 2, 2012
lib better close handling Jun 2, 2012
src removed need for uv_ref and uv_unref Jun 2, 2012
test osx working Apr 26, 2012
.gitignore initial commit Apr 24, 2012 Update Jul 22, 2012
binding.gyp Remove duplicate target source file Jul 14, 2012
index.js initial commit Apr 24, 2012
package.json new version Jun 2, 2012

NOTE: This project has merged with serialport. Future development will continue there. I will be depricating this module in the future.


Node.js serial port driver. Works on Windows, OSX, and linux.


npm install serialport2

Note for windows users. If you are using Node v0.6.x you will need to have Python 2.7 installed. See node-gyp for instruction on getting a working node-gyp environment.

Note for beagleboard/bone users. You may have to install the python-compiler package (opkg install python-compiler).

Quick Example

var SerialPort = require('serialport2').SerialPort;
var port = new SerialPort();

port.on('data', function(data) {

port.on('error', function(err) {
});'COM4', {
  baudRate: 9600,
  dataBits: 8,
  parity: 'none',
  stopBits: 1
}, function(err) {
  port.write("hello world");
var sp = require('../');
sp.list(function(err, ports) {



new SerialPort()

Creates the serial port.

open(portName, [options], [callback])

Open the serial port.


  • portName - The name of the port to open. Example: Windows 'COM1', Linux '/dev/ttyUSB0'.
  • options - Options for open
    • baudRate - The baud rate [default: 9600]
    • dataBits - The data bits [default: 8]
    • parity - The parity, can be (none, odd, even) [default: 'none']
    • stopBits - The number of stop bits, can be (1, 1.5, 2) [default: 1]
    • flowControl - Enable flow control (true, false) [default: false]
  • callback(err) - Callback called after opening the port.

write(buffer, [callback])

Writes data to the serial port.


  • buffer - This can be a node Buffer object or a string.
  • callback(err, byteWritten) - Callback called after writing bytes.

NOTE: When calling write multiple times sequentially, you must ensure the previous write call has completed, or byte ordering may not be preserved. This may be fixed in future versions.


Closes the serial port.


  • callback(err) - Callback called after the port is closed.

Event: data

Event emitted by SerialPort when data is available. The first argument will contain a Buffer with the data.

Event: error

Event emitted by SerialPort if an error occurs. The first argument will contain the error.


Lists the serial ports on the machine.


  • callback(err, ports) - Callback called after the list is retrieved.
You can’t perform that action at this time.