title: nodemon app crashed - waiting for file changes before starting
body: <p><strong>EDIT</strong>
  After further testing, I have found that this is happening with both gulp and grunt on this app and on the default install of mean.js.  I'm running this locally on a Mac.  When I running either app using "node server.js" they don't crash.</p>
  
  <p>I'm using a MEAN stack with grunt-nodemon and node is crashing when an express URL is accessed.  It isn't always consistent though.  Sometimes it works, sometimes node crashes right when the URL is hit retiring no data, and other times I get a response and node crashed immediately after.</p>
  
  <p><strong>Browser console response:</strong> </p>
  
  <pre><code>http://localhost:8000/api/users net::ERR_CONNECTION_REFUSED
  </code></pre>
  
  <p><strong>Terminal output:</strong></p>
  
  <pre><code>Mongoose: users.insert({ firstname: 'mike', lastname: 'jones', email:'mike@gmail.com', role: 'admin', password: 'mike', _id: ObjectId("57485c16fc11894b96c28057"), created: new Date("Fri, 27 May 2016 14:39:18 GMT"), __v: 0 })   
  user.save success
  node crash
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>
  
  <p>In this case, the POST request went through, the user was added, then node crashed, but sometimes it crashes before a successful POST.  Node also occasionally crashes on the GET request.  </p>
  
  <p><strong>gruntfile.js:</strong></p>
  
  <pre><code>module.exports = function(grunt) {
      // Load grunt tasks automatically
      require('load-grunt-tasks')(grunt);
  
      var pkg = grunt.file.readJSON('package.json');
  
      var options = {
          paths: {
              app: 'app',
              assets: 'app/assets',
              dist: 'app/dist',
              distAssets: 'app/dist/assets',
              html: 'app/html',
              htmlTmp: '.tmp/htmlsnapshot',
              htmlAssets: 'app/html/assets',
              index: 'app/dist/index.html',
              indexDev: 'app/index.html',
              indexTmp: '.tmp/html/index.html'
          },
          pkg: pkg,
          env: {
              test: {
                  NODE_ENV: 'test'
              },
              dev: {
                  NODE_ENV: 'development'
              },
              prod: {
                  NODE_ENV: 'production'
              }
          }
      };
  
      // Load grunt configurations automatically
      var configs = require('load-grunt-configs')(grunt, options);
  
      // Define the configuration for all the tasks
      grunt.initConfig(configs);
  
      // Connect to the MongoDB instance and load the models
      grunt.task.registerTask('mongoose', 'Task that connects to the MongoDB instance and loads the application models.', function () {
          // Get the callback
          var done = this.async();
  
          // Use mongoose configuration
          var mongoose = require('./config/lib/mongoose.js');
  
          // Connect to database
          mongoose.connect(function (db) {
              done();
          });
      });
  
      grunt.registerTask('bumper', ['bump-only']);
      grunt.registerTask('css', ['sass']);
      grunt.registerTask('default', [
          'sass',
          'copy:dev',
          'nodemon',
          'concurrent:dev',
          'watch',
          'mongoose'
      ]);
  
      grunt.registerTask('shared', [
          'clean:demo',
          'copy:demo',
          'sass',
          'ngconstant',
          'useminPrepare',
          'concat:generated',
          'cssmin:generated',
          'uglify:generated',
          'filerev',
          'usemin',
          'imagemin',
          'usebanner'
      ]);
  
      grunt.registerTask('demo', [
          'shared',
          'copy:postusemin',
          'grep:demo'
      ]);
  
      grunt.registerTask('dist', [
          'shared',
          'copy:postusemin',
          'copy:dist',
          'grep:dist',
          'compress',
          'copy:postusemin',
          'grep:demo',
      ]);
  
      grunt.loadNpmTasks('grunt-forever');
  
  };
  </code></pre>
  
  <p><strong>default.js</strong></p>
  
  <pre><code>module.exports.tasks = {
      // version update
      bump: {
          options: {
              files: ['package.json', 'bower.json'],
              pushTo: 'origin'
          }
      },
  
      // application constants
      ngconstant: {
          options: {
              dest: '&lt;%= paths.assets %&gt;/js/app.constants.js',
              name: 'app.constants',
          }
      },
  
      // remove all bs from css
      cssmin: {
          options: {
              keepSpecialComments: 0
          }
      },
      markdown: {
          all: {
              files: [
                  {
                      src: 'README.md',
                      dest: '&lt;%= paths.assets %&gt;/tpl/documentation.html'
                  }
              ],
              options: {
                  template: '&lt;%= paths.assets %&gt;/tpl/_documentation_template.html',
              }
          }
      }
  };
  </code></pre>
  
  <p><strong>dev.js:</strong></p>
  
  <pre><code>var _ = require('lodash'),
  defaultAssets = require('./assets/default'),
  testAssets = require('./assets/test'),
  testConfig = require('./env/test'),
  fs = require('fs'),
  path = require('path');
  
  module.exports.tasks = {
      // copy files to correct folders
      copy: {
          dev: {
              files: [
                  { expand: true, src: '**', cwd: '&lt;%= paths.app %&gt;/bower_components/font-awesome/fonts',                    dest: '&lt;%= paths.assets %&gt;/fonts' },
                  { expand: true, src: '**', cwd: '&lt;%= paths.app %&gt;/bower_components/material-design-iconic-font/fonts',     dest: '&lt;%= paths.assets %&gt;/fonts' },
                  { expand: true, src: '**', cwd: '&lt;%= paths.app %&gt;/bower_components/roboto-fontface/fonts',                 dest: '&lt;%= paths.assets %&gt;/fonts' },
                  { expand: true, src: '**', cwd: '&lt;%= paths.app %&gt;/bower_components/weather-icons/font',                    dest: '&lt;%= paths.assets %&gt;/fonts' },
                  { expand: true, src: '**', cwd: '&lt;%= paths.app %&gt;/bower_components/bootstrap-sass/assets/fonts/bootstrap', dest: '&lt;%= paths.assets %&gt;/fonts' }
              ]
          }
      },
  
      // watch for changes during development
      watch: {
          js: {
              files: ['Gruntfile.js', '&lt;%= paths.assets %&gt;/js/**/*.js'],
              tasks: ['jshint'],
              options: {
                  livereload: true
              }
          },
          css: {
              files: [
                  '&lt;%= paths.assets %&gt;/css/**/*.scss'
              ],
              tasks: ['sass'],
              options: {
                  livereload: true
              }
          },
          markdown: {
              files: [
                  'README.md'
              ],
              tasks: ['markdown']
          },
          tasks:  [ 'express:dev' ],
      },
  
      // debug while developing
      jshint: {
          all: ['Gruntfile.js', '&lt;%= paths.assets %&gt;/js/**/*.js']
      },
      concurrent: {
          dev: {
              tasks: ['nodemon', 'node-inspector', 'watch'],
              options: {
                  logConcurrentOutput: true
              }
          }
      },
      nodemon: {
          dev: {
              script: 'server.js',
              options: {
                  nodeArgs: ['--debug'],
                  ext: 'js,html',
                  callback: function (nodemon) {
  
                      nodemon.on('crash', function (event) {
                          console.log(event);
                      });
  
  
                  },
                  watch: _.union(defaultAssets.server.gruntConfig, defaultAssets.server.views, defaultAssets.server.allJS, defaultAssets.server.config)
              }
          }
      },
      forever: {
          server1: {
              options: {
                  index: 'server.js',
                  //logDir: 'logs'
              }
          }
      }
  };
  </code></pre>
  
  <p><strong>Angular controller function:</strong></p>
  
  <pre><code>  $scope.addUser = function(){
  
        var user = {
            firstname: $scope.firstname,
            lastname: $scope.lastname,
            email: $scope.email,
            role: $scope.role.selected,
            password: $scope.password
        };
  
        $http.post('/api/userAdd', user ).then(function successCallback(response) {
            $location.path('/users');
        }, function errorCallback(response) {
            console.log('error addding user');
            console.log(response);
        });
    };
  </code></pre>
  
  <p><strong>Express route:</strong> </p>
  
  <pre><code>User = require('../models/user.js');
  
  module.exports = function (app) {
  
      app.get('/api/users', function (req, res) {
  
          User.find({}, function (err, users) {
              if ( err ) {
                  res.send({
                      message : 'error finding users',
                      success: false
                  });
              } else {
                  res.json(users);
              }
          });
  
      });
  
      app.get('/api/users', function (req, res) {
          User.find({fields: {}}, function (err, docs) {
              res.json(docs);
          });
      });
  
      app.post('/api/userAdd', function (req, res) {
  
          var user = new User(req.body);
  
          user.save( function( err, user ){
  
              if (err){
                  console.log('user.save error');
                  console.log(err);
                  res.send({
                      success: false
                  });
              } else {
                  console.log('user.save success');
                  res.send({
                      success: true
                  });
              }
          });
  
      });
  
  };
  </code></pre>
  
  <p>I'm also testing with Chromes Advanced REST extension and with any request using this tool node crashes immediately.  </p>
  
  <p>I'm new to MEAN so am I missing something here that is causing the crash?  Any ideas? </p>