Skip to content

Instantly share code, notes, and snippets.

@manjeshpv
Created March 27, 2019 13:19
Show Gist options
  • Save manjeshpv/8711c39a811a40a0709f736700091dd7 to your computer and use it in GitHub Desktop.
Save manjeshpv/8711c39a811a40a0709f736700091dd7 to your computer and use it in GitHub Desktop.
const { MongoMemoryServer } = require('mongodb-memory-server');
console.log(MongoMemoryServer)
const mongod = new MongoMemoryServer();
const x = async() => {
const uri = await mongod.getConnectionString();
const port = await mongod.getPort();
const dbPath = await mongod.getDbPath();
const dbName = await mongod.getDbName();
// some code
// ... where you may use `uri` for as a connection string for mongodb or mongoose
// you may check instance status, after you got `uri` it must be `true`
console.log(uri); // return Object with instance data
// you may stop mongod manually
// await mongod.stop();
// when mongod killed, it's running status should be `false`
mongod.getInstanceInfo();
}
x()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment