Here’s how I set up the Mean.io stack for deployment with Dokku.

  • Set up MongoDB on the Dokku host and create a database. I used Jeff Utter’s single container plugin for this.

    $ dokku mongodb:start
    $ dokku mongodb:create <app> <database>
    $ dokku mongodb:link <app> <database>
    
  • Modify config/env/production.js to use ENV var for MongoDB URL:

    'use strict';
    
    module.exports = {
      db: process.env.MONGO_URL,
    
    // [REST OF FILE ELIDED]
    
  • Configure the application to run in the production environment:

    $ dokku config:set <app> NODE_ENV=production
    
  • Set the unsafe-perm npm configuration option to allow npm to operate under the root account. More information here. Create .npmrc as follows:

    unsafe-perm = true
    
  • Configure a buildpack which supports Grunt in .env:

    BUILDPACK_URL=https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt.git
    
  • Add Heroku build task without environment to Gruntfile.js since Dokku doesn’t read config during build steps:

      // [REST OF FILE ELIDED]
    
      // For Heroku users only.
      // Docs: https://github.com/linnovate/mean/wiki/Deploying-on-Heroku
      grunt.registerTask('heroku:production', ['cssmin', 'uglify']);
    
      // Dokku does not set ENV vars during build steps:
      grunt.registerTask('heroku:', ['cssmin', 'uglify']);
    };