```ts
const MODULUS = 1000000007;

/**
 * The nth Fibonacci number, modulo 1000000007. fibMod(0) === 0 and fibMod(1) === 1.
 * Returns an Error if n is not a non-negative integer.
 */
export function fibMod(n: number): number {
  if (!Number.isInteger(n)) {
    throw new Error('n must be a non-negative integer');
  }
  if (n < 2) {
    return n;
  }

  let a = 0, b = 1; // Initialize the first two Fibonacci numbers
  for (let i = 2; i <= n; ++i) {
    const temp = (a + b) % MODULUS; // Use modulo to avoid overflow
    a = b;
    b = temp;
  }
  return b;
}
```