Random-js is not a function

Asked by At

Previously, everything worked, but now something is wrong. Node version - 10.4 Error:

var random = require("random-js")();
                                 ^
TypeError: require(...) is not a function

Code:

var random = require("random-js")();

For this:

    function getRandom() {
    reGeneratePatern();
    gencode = numbers[Math.floor(Math.random() * numbers.length)];
    return gencode;
}

Wtf?

1 Answers

2
Maheer Ali On

If you use Usage of this module you will notice it returns an object.

So you should use

var random = require("random-js");

If you want to get Random method you can use Object Destructuring

const { Random } = require("random-js");