const bluetooth = require('node-bluetooth'); //console.log(bluetooth) const device = new bluetooth.DeviceINQ(); try { device .on('finished', console.log.bind(console, 'finished')) .on('found', function found(address, name){ console.log('Found: ' + address + ' with name ' + name); // find serial port channel device.findSerialPortChannel(address, function(channel) { console.log('Found RFCOMM channel for serial port on %s: ', name, channel); // make bluetooth connect to remote device try { bluetooth.connect(address, channel, function (err, connection) { if (err) return console.error(err); connection.delimiter = Buffer.from('\n', 'utf8'); connection.on('data', (buffer) => { console.log('received message:', buffer.toString()); }); connection.write(new Buffer('Hello!', 'utf-8'), () => { console.log('wrote'); }); }); } catch (e) { console.log(123123) console.log(e) } }); }) device.scan(); } catch (err) { console.log(err) }