node.jsbigint

BigInt in node 12 (v12.22.12)


I'd like to use BigInt with node 12.22.12. It works fine in the REPL but in my script I need to "require" it. I tried things like const BigInt = require('BigInt') or require('node:bigint') and different mixes but it's not working...


Solution

  • BigInt is a core part of the JS language (built into the interpreter itself). You don't require() it. You can just use it as in:

    let x = BigInt("9007199254740991");
    let y = 9007199254740991n;
    
    console.log(x, y);