TypeError: brain.NeuralNetwork is not a constructor

I am new to Machine Learning.

Having followed the steps in this simple Maching Learning using the Brain.js library, it beats my understanding why I keep getting the error message below:

enter image description here

I have double-checked my code multiple times. This is particularly frustrating as this is the very first exercise!

Kindly point out what I am missing here!

Find below my code:

const brain = require('brain.js');

var net = new brain.NeuralNetwork();

net.train([
  { input: [0, 0], output: [0] },
  { input: [0, 1], output: [1] },
  { input: [1, 0], output: [1] },
  { input: [1, 1], output: [0] },
]);

var output = net.run([1, 0]); // [0.987]

console.log(output);

I am running Nodejs version v14.17.4

Answer

Turns out its just documented incorrectly.

In reality the export from brain.js is this:

{
  brain: { ...brain class },
  default: { ...brain class again }
}

So in order to get it working properly, you should do

const brain = require('brain.js').brain // access to nested object
const net = new brain.NeuralNetwork()