Search code examples
node.jspm2

How to use pm2 in grunt with a mean.js setup?


i used yo generator to install a skeleton mean js program with a grunt build to do the minifications and deployment.

What is the steps to be taken to deploy with pm2?

Right now im using nodemon to keep my app alive and im using digitalocean console stream to run the following command:

NODE_ENV=production PORT:80 grunt --force

That does according to my gruntfile the following:

    concurrent: {
        default: ['nodemon', 'watch'],
        options: {
            logConcurrentOutput: true
        }
    },

....

nodemon: {
            dev: {
                script: 'server.js',
                options: {
                    //nodeArgs: ['--debug'],
                    ext: 'js,html',
                    watch: watchFiles.serverViews.concat(watchFiles.serverJS)
                }
            }
        },

grunt.registerTask('default', ['sass','lint', 'concurrent:default']);

What configuration should i add/change in my gruntfile to make all of this work with pm2? ( I need it for clustering and load-balance my app ).


Solution

  • On the command line do:

    $ export NODE_ENV=production
    

    will setup production environmental

    $ grunt build
    

    will create necessary .min.js and min.css

    $ pm2 start server.js
    

    will load the server with pm2, that its a package thats makes sure the node server will restart if an error and will log.