DEV Community

Discussion on: Setup in-memory database for testing Node.js and Mongoose

Collapse
 
ryuuto829 profile image
Dmytro Rykhlyk

Thank you for your comment!
I've updated article using the latest @7.2.1 version of mongodb-memory-server.
Basically, I define a new instance of "MongoMemoryServer" in the connect async function to automatically start server:

/tests/db.js

- const mongoServer = new MongoMemoryServer();
+ let mongoServer;

const connect = async () => {
  await mongoose.disconnect();
+ mongoServer = await MongoMemoryServer.create();

// ...
};
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tperrinweembi profile image
tperrin

Ok! thanks a lot for your answer