forked from vikingeducation/assignment_thoreddit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepl.js
More file actions
48 lines (45 loc) · 1.26 KB
/
repl.js
File metadata and controls
48 lines (45 loc) · 1.26 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const lodash = require("lodash");
const helpers = require("./helpers");
const mongoose = require("mongoose");
const repl = require("repl").start({});
const models = require("./models");
require("./mongo")().then(() => {
// Set `models` to be available in
// the REPL by name
repl.context.models = models;
// Set each model to be available in the REPL
// by name
Object.keys(models).forEach(modelName => {
repl.context[modelName] = mongoose.model(modelName);
});
// Helper function to output the result of
// a query
repl.context._lg = name => {
return results => {
console.log("*****************");
console.log(name);
console.log("********************");
console.log(results);
console.log("********************");
console.log();
return results;
};
};
repl.context.lg = data => {
let newData;
newData = data;
console.log(newData);
console.log(data);
};
});
// ----------------------------------------
// Libs
// ----------------------------------------
repl.context.lodash = lodash;
// ----------------------------------------
// Helpers
// ----------------------------------------
repl.context.helpers = helpers;
Object.keys(helpers).forEach(key => {
repl.context[key] = helpers[key];
});