I'm trying to use the module as described in docs.
const MongodbMemoryServer = require('mongodb-memory-server');
const mongoServer = new MongodbMemoryServer();
But I got the error TypeError: MongodbMemoryServer is not a constructor.
At this page I've found another piece of code
const mongoServer = new MongodbMemoryServer.MongoMemoryServer();
and that works. Is that an error in the documentation or in the code?
@kbychkov The documentation is actually using the ES6 equivalent syntax of require that is import :
import MongodbMemoryServer from 'mongodb-memory-server';
const mongod = new MongodbMemoryServer();
By using import like that, it is actually importing the default export of the mongodb-memory-server library that is MongodbMemoryServer. A easy way to do that with require is this :
const MongodbMemoryServer = require('mongodb-memory-server').default
const mongoServer = new MongodbMemoryServer()
Ahhh, I see. Thank you for the explanation!
Also, it is possible to use:
const { MongoMemoryServer } = require('mongodb-memory-server');
It worked for me.
Most helpful comment
Also, it is possible to use:
It worked for me.