For a while I was using VirtualBox/Vagrant for development projects. More recently I’ve moved to using Docker. I use Linux (lubuntu) on my dev computer anyways, so it was an easy transition and the resource consumption is significantly lower. …

I’m using the Yeoman angular-fullstack generator for a MEAN project that I’m working on and I wanted to be able to mock the database connection for quicker testing. I found mockgoose, but I wasn’t clear on how to implement it in this environment. Without further ado, here are the steps.

First, install mockgoose with npm:

npm install mockgoose --save-dev

Open the file {project-base}/server/app.js and find the block starting with // Connect to database:

mongoose.connect(config.mongo.uri, config.mongo.options);
mongoose.connection.on(‘error’, function(err) {
console.error(‘MongoDB connection error: ‘ + err);
process.exit(-1);
}
);

Edit this block to the following:

if (process.env.NODE_ENV == ‘test’) {
var mockgoose = require(‘mockgoose’)(mongoose);
mongoose.connect(config.mongo.uri);
} else {
mongoose.connect(config.mongo.uri, config.mongo.options);
mongoose.connection.on(‘error’, function(err) {
console.error(‘MongoDB connection error: ‘ + err);
process.exit(-1);
}
);
}

That’s it! I’m working on a micro cloud instance, so changing to mockgoose took my test run time from 88 seconds to 2.3 seconds.

A few weeks ago, I decided to jump into Ember.js and try my hand at building a fully client-side app. The tutorial on Ember’s site that walks through an implementation of TodoMVC is well written and has good depth, but it is somewhat outdated. …

Bill Broughton

Full-stack developer, creator of http://wfplsiu.com, co-teacher @ Ghost Influence, family man, car and motorcycle enthusiast

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store