RunJS notes & snippets draft

Last modified 5 months ago / Edit on Github
Danger icon
This is a draft, the content is not complete and of poor quality!
On this page
  1. MongoDB
  2. Lodash

RunJS is a wonderful playground application for testing quickly JavaScript and NodeJS.

MongoDB

👉 MongoDB official note

Setting up the environement variables first.

async function initMongoDb() {
const uri = `mongodb+srv://${process.env.IDETA_MONGO_USER}:${process.env.IDETA_MONGO_PASSWORD}@${process.env.IDETA_MONGO_HOST}`;
console.log(uri);
try {
const client = await MongoClient.connect(uri, {
useUnifiedTopology: true
});
return { client, db: client.db(`${process.env.IDETA_MONGO_DATABASE}`) };
} catch (e) {
throw e;
}
}

async function testMongo() {
const mongo = await initMongoDb();
return mongo.db.collection('agents').findOne({ active: false });
}

async function main() {
const agent = await testMongo();
console.log(agent);
}

main();

Lodash

👉 Lodash doc.

var _ = require('lodash');
// and then test with snippets on the doc
_.chunk(['a', 'b', 'c', 'd'], 2);

💬 Comments

Support Thi Support Thi