Skip to content

Instantly share code, notes, and snippets.

@the-architect
Last active May 3, 2020 10:18
Show Gist options
  • Save the-architect/bbdceea1d115cd341520b5028de3c6d2 to your computer and use it in GitHub Desktop.
Save the-architect/bbdceea1d115cd341520b5028de3c6d2 to your computer and use it in GitHub Desktop.
Mongoose REPL
// 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({});
@the-architect
Copy link
Author

run with async/await support: node --experimental-repl-await repl.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment