Skip to content

Instantly share code, notes, and snippets.

Last active Sep 29, 2017
What would you like to do?
Teaching :) - Example of Express server with SerialPort reading

Express server and serial port reading

This JS file demonstrate how open a serial port to read it, and display read value over HTTP server.

Copy/Paste the script will display value at : http://localhost:3000 enjoy.


yarn add serialport
yarn add express


npm install serialport
npm install express


node yourFile.js
//Define requires
const express = require('express')
const serialport = require('serialport');
//Store Arduino data
var myData = 0;
//Setup and start web server on :3000
const app = express()
app.get('/', function (req, res) { res.send('Hello World! - Valeur : ' + myData) });
app.listen(3000, function () { console.log('Example app listening on port 3000!') });
//Setup and start serial port reading
const Readline = serialport.parsers.Readline;
const parser = new Readline();
var mySerialPort = new serialport("/dev/ttyUSB0", {
baudRate: 9600,
dataBits: 8,
parity: 'none',
stopBits: 1,
flowControl: false,
parser.on('data', function(input) {
console.log("Data :", input);
myData = input;
void setup() {
// put your setup code here, to run once:
void loop() {
// put your main code here, to run repeatedly:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment