2

I am just playing with MEAN stack but I can't figure out how to run my app in production mode to perform some benchmarking. Site mean.io says:

To run with a different environment, just specify NODE_ENV as you call grunt:

$ NODE_ENV=test grunt

How can I pass the variable to grunt?

Edit: I am using Windows

svobol13
  • 1,842
  • 3
  • 25
  • 40

2 Answers2

8

To decide if the application runs in production or development mode, it checks the NODE_ENV environment variable, which is a variable that you'll set in your shell and that will be read from node.

If you want to run grunt in production mode, use:

$ NODE_ENV=production grunt

which will set the variable only for this execution.

If you want to permanently set NODE_ENV, use export:

$ export NODE_ENV=production
$ grunt

On your production server, you can then edit .bashrc with this line to permanently set NODE_ENV.

For further information, you can read this blog post.

Edit: On Windows, use set NODE_ENV=production on the command line. See this relevant question to know how to permanently set this variable.

Community
  • 1
  • 1
Paul Mougel
  • 16,728
  • 6
  • 57
  • 64
  • I see. I missed that it is the bash/shell command. I forgot to mention that I am using cmd.exe :) – svobol13 Nov 29 '13 at 15:02
  • 1
    Updated my answer for Windows then. – Paul Mougel Nov 29 '13 at 15:11
  • You shouldn't need sudo to set the `NODE_ENV` variable. However, if in production you use a restricted port (< 1024), then you will need root privileges to listen on this port. See [this question](http://stackoverflow.com/questions/16573668/best-practices-when-running-node-js-with-port-80-ubuntu-linode) for instance. – Paul Mougel May 09 '16 at 08:03
0

The following command works in my case:

grunt prod

Notice that I use mean.js version 0.4.2 and found this config in file $HOME_PROJECT_FOLDER/gruntfile.js

Tho
  • 23,158
  • 6
  • 60
  • 47