Search code examples
node.jsgruntjsgrunt-contrib-watchmeanjsnodemon

My meanjs server takes 3-6 minutes to start


My mean.js app is based off the yoeman meanjs generator, with some tweaks (e.g. separating the front end and backend so they can be deployed separately).

I'm launching the app using fig (see fig.yml below). When I set the command to "node server.js", the server takes 6 seconds to starts.

When I startup using "grunt", which runs nodemon and watch, it takes about 6 minutes. I've tried various things but can't really understand why nodemon would cause things to run so much slower

fig.yml:

web:
  build: .
  links:
   - db:mongo.local
  ports:
   - "3000:3000"
  volumes:
   - .:/home/abilitie
  command: grunt
  #command: node server.js # much faster but you don't get the restart stuff
  environment: 
   NODE_ENV: development
db:
  image: dockerfile/mongodb
  ports: 
   - "27017:27017"

Gruntfile (excerpt)

concurrent: {
    default: ['nodemon', 'watch'],
    old_default: ['nodemon', 'watch'],
    debug: ['nodemon:debug', 'watch', 'node-inspector'],
    options: {
        logConcurrentOutput: true,
        limit: 10
    }
},

jshint: {
    all: {
        src: watchFiles.serverJS,
        options: {
            jshintrc: true
        }
    }
},

grunt.registerTask('lint', ['jshint']);
// Default task(s).
grunt.registerTask('default', ['lint', 'concurrent:default']);

Solution

  • NFS saved the day.

    The VirtualBox shared folder is super slow. Using this vagrant image instead of boot2docker is much faster.

    https://vagrantcloud.com/yungsang/boxes/boot2docker

    Also, make sure to disable UDP, or NFS may hang. You may do so by putting this in your Vagrantfile:

    config.vm.synced_folder ".", "/vagrant", type: "nfs", nfs_udp: false