This trivial example shows how to open a MIDI device for input and then respond to its events. Here we simply print out the MIDI traffic which is a great way to learn about MIDI or better understand aspects of your devices.
let port = 0;
let midiInput = new MidiIn(port);
let ok = await midiInput.Open();
console.log("midiInput.open returned " + ok);
for(let i=0;i<30;i++)
{
let data = await midiInput.Recv(); // "blocks" until activity
console.log(`${i}: ${data}`);
}
console.log("midiInput.close");
midiInput.Close();