Skip to content

Instantly share code, notes, and snippets.

View blackwright's full-sized avatar
🌌
machine drawing

Jerry Gao blackwright

🌌
machine drawing
View GitHub Profile
@blackwright
blackwright / clean.js
Created April 28, 2017 15:24
Mongoose Seeds Clean
const mongoose = require('mongoose');
module.exports = () => {
// Get all collections
let collections = mongoose
.connection
.collections;
// Get collection names
@blackwright
blackwright / index.js
Created April 28, 2017 14:38
Mongoose Seeds Index
const mongoose = require('mongoose');
const models = require('../models');
Object.keys(models).forEach((modelName) => {
global[modelName] = mongoose.model(modelName);
});
require('../mongo')()
.then(() => console.log('Cleaning Database...'))
.then(() => {
@blackwright
blackwright / repl.js
Last active April 28, 2017 14:35
Mongoose REPL
var mongoose = require('mongoose');
var repl = require('repl').start({});
var models = require('./models');
require('./mongo')().then(() => {
repl.context.models = models;
Object.keys(models).forEach((modelName) => {
repl.context[modelName] = mongoose.model(modelName);
});
@blackwright
blackwright / mongo.js
Created April 28, 2017 14:19
Mongoose Config
const mongoose = require("mongoose");
const env = process.env.NODE_ENV || "development";
const config = require("./config/mongo")[env];
module.exports = () => {
const envUrl = process.env[config.use_env_variable];
const localUrl = `mongodb://${config.host}/${config.database}`;
const mongoUrl = envUrl ? envUrl : localUrl;
return mongoose.connect(mongoUrl);
};
@blackwright
blackwright / index.js
Created April 28, 2017 14:03
Helpers Index
const fs = require('fs');
const path = require('path');
const express = require('express');
const basename = path.basename(__filename);
const Helpers = {};
// Object to hold registered helpers
Helpers.registered = {};
@blackwright
blackwright / repl.js
Last active April 7, 2020 10:10
Sequelize REPL
// Require the REPL module
// and models
let repl = require('repl').start({});
const models = require('./models');
// Make the `models` object
// a global variable in the
// REPL
repl.context.models = models;
@blackwright
blackwright / app.js
Last active April 29, 2017 01:18
Express Handlebars Template
const express = require('express');
const app = express();
// ----------------------------------------
// Dotenv
// ----------------------------------------
if (process.env.NODE_ENV !== "production") {
require("dotenv").config();
}