Getting Error EBUSY: resource busy or locked

var onoff = require('onoff');
var Gpio = onoff.Gpio,
    led = new Gpio(4, 'out'),
    interval;
interval = setInterval(function () {
    var value = (led.readSync() + 1) % 2;
    led.write(value, function () {
        console.log("Changed LED state to: " + value);
    });
}, 2000);
process.on('SIGINT', function () {
    clearInterval(interval);
    led.writeSync(0);
    led.unexport();
    console.log('Bye, bye!');
    process.exit();
});

There are many answers on GitHub regarding this issue.

  • Some says npm cache clean this command executing on terminal solved the problem.

  • Others recommend to delete the entire directory your app is the folder in and re-install the packages and then try running the program.

  • Some also says that It is caused by the anti-malware software and recommend to disable it while running the program.

GitHub issue link: https://github.com/npm/npm/issues/13461

If it doesn't solve the issue, just change the GPIO pin to let's say 23 in coding and don't forget to physically replace LED from 4 to 23 too.


This problem can occur when you try to write to a file that is open in an editor