-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdev-mongo.js
More file actions
32 lines (27 loc) · 877 Bytes
/
dev-mongo.js
File metadata and controls
32 lines (27 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require("dotenv").config({ path: "./config/.env" });
const { MongoMemoryServer } = require('mongodb-memory-server');
const fs = require('fs');
const path = require('path');
async function run() {
const dbString = process.env.DB_STRING || ''
if (!dbString.includes('localhost') && !dbString.includes('127.0.0.1')) {
console.log('DB_STRING is not localhost, not running local mongo')
return
}
const dbPath = path.join(__dirname, '..', '.mongo');
if (!fs.existsSync(dbPath)) {
fs.mkdirSync(dbPath);
}
// start mongo
const mongod = await MongoMemoryServer.create({
instance: {
port: 27017,
dbPath,
// to persist data between runs (https://github.com/nodkz/mongodb-memory-server/issues/524)
storageEngine: 'wiredTiger',
},
});
const uri = mongod.getUri();
console.log(`Mongo server started on: ${uri}`);
}
run()