```ts
import { strict as assert } from 'assert';

const MODULUS = 1000000007;

/** The nth Fibonacci number, modulo 1000000007. */
export function fibMod(n: number): number {
  if (!Number.isInteger(n) || n < 0) {
    throw new Error('n must be a non-negative integer');
  }

  let a = 0;
  let b = 1;

  for (let i = 2; i <= n; ++i) {
    const next = (a + b) % MODULUS;
    a = b;
    b = next;
  }

  return b;
}

// Check function to verify the correctness of the solution
function checkFibMod() {
  assert.equal(fibMod(0), 0);
  assert.equal(fibMod(1), 1);
  assert.equal(fibMod(2), 1);
  assert.equal(fibMod(3), 2);
  assert.equal(fibMod(4), 3);
  assert.equal(fibMod(5), 5);
  // Add more checks as needed
}

checkFibMod();
```