node package manager
Stop writing boring code. Discover, share, and reuse within your team. Create a free org ยป


Web MIDI API for Node.js

nodejs windows macos linux

This is a Node.js implementation of Web MIDI API (as in Chrome-43 version).

It is based on Chris Wilson's WebMIDIAPIShim.

The complete development and web-browser versions are available at cwilso/WebMIDIAPIShim (the original project), or jazz-soft/WebMIDIAPIShim (the latest Node.js updates) - these two get merged periodically.


npm install web-midi-api

var navigator = require('web-midi-api');

var midi;
var inputs;
var outputs;

function onMIDIFailure(msg){
  console.log('Failed to get MIDI access - ' + msg);

function onMIDISuccess(midiAccess){
  midi = midiAccess;
  inputs = midi.inputs;
  outputs = midi.outputs;
  setTimeout(testOutputs, 500);

function testOutputs(){
  console.log('Testing MIDI-Out ports...');
    console.log('id:',, 'manufacturer:', port.manufacturer, 'name:',, 'version:', port.version);;
    port.send([0x90, 60, 0x7f]);
  setTimeout(stopOutputs, 1000);

function stopOutputs(){
    port.send([0x80, 60, 0]);

function onMidiIn(ev){
  var arr = [];
  for(var i = 0; i <; i++){
    arr.push(([i] < 16 ? '0' : '') +[i].toString(16));
  console.log('MIDI:', arr.join(' '));

function testInputs(){
  console.log('Testing MIDI-In ports...');
    console.log('id:',, 'manufacturer:', port.manufacturer, 'name:',, 'version:', port.version);
    port.onmidimessage = onMidiIn;
  setTimeout(stopInputs, 5000);

function stopInputs(){
  console.log('Thank you!');
  navigator.close(); // This will close MIDI inputs, otherwise Node.js will wait for MIDI input forever.

navigator.requestMIDIAccess().then(onMIDISuccess, onMIDIFailure);