Last active
May 3, 2020 10:18
-
-
Save the-architect/bbdceea1d115cd341520b5028de3c6d2 to your computer and use it in GitHub Desktop.
Mongoose REPL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load environment variables from .env file | |
require('dotenv').config(); | |
// load mongoose and connect to db using env variable | |
const mongoose = require('mongoose'); | |
mongoose.connect(process.env.MONGODB_CONNECTION, { useNewUrlParser: true, useUnifiedTopology: true }); | |
// start the node repl | |
const repl = require('repl'); | |
const context = repl.start().context; | |
// load mongoose User model | |
const { User } = require('./lib/models/user'); | |
// add mongoose User model to repl context: | |
context.User = User; | |
context.mongoose = mongoose; | |
// start with: node --experimental-repl-await repl.js | |
// use the User model: await User.find({}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
run with async/await support:
node --experimental-repl-await repl.js