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


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

For this:

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


1 Answers

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");