const Gpio = require('onoff').Gpio;

const
  ON  = 1,
  OFF = 0;

const led4 = new Gpio(4, 'out');
const button17 = new Gpio(17, 'in', 'both');

const blink = (led, value = 1) => {
  led.write(value, () => {
    console.log(`led ${value}`)
    setTimeout(() => blink(led, value ? 0 : 1), 1000);
  });
};

blink(led4, 1);

button17.watch((err, value) => {
  if (err) {
    console.error(err);
  }

  console.log('button change', value);
});

process.on('SIGINT', () => {
  led4.unexport();
});

const Gpio = require('onoff').Gpio;

const ON_INTERVAL = 4000;

const led4 = new Gpio(4, 'out');
const button17 = new Gpio(17, 'in', 'both');

const actionLed = (value) => (led) => {
  led.write(value, () => {
    console.log(`led ${value}`);
  });
};

const
  on = actionLed(1),
  off = actionLed(0);

off(led4);

setInterval(() => on(led4), ON_INTERVAL);

button17.watch((err) => {
  if (err) {
    console.error('button error', err);
  }

  off(led4);
});

process.on('SIGINT', () => {
  led4.unexport();
});

Use button to switch the led off
Use button to switch the led off
