Running our application on the local server is fine, but making a web application really useful requires deploying it to a public server and making it accessible to others. To run our chat server application on Node.js, along with using protocols such as WebSocket, requires some special considerations. In this chapter, we will take a look at the following:
The first thing we should do before running an application on a production server is to set the environment to production
. Every modern server or framework has separate development and production modes and so does node. In fact, in node you can set the environment to any name and then have different configurations for that name in your code. To set the environment our node server runs in, we set an environment variable NODE_ENV
to the environment we want to run node in. So, to run node in the production
environment, we use the following line:
$ export NODE_ENV=production
And then run your node application. In Chapter 2, Getting Started with Node.js, we saw how the first argument in app.configure
is the environment variable we need to configure for:
app.configure('development', function(){ app.use(express.errorHandler()); });
In this snippet we are setting the application to activate express.errorHandler
in the development
environment, which is the default environment. If we have set NODE_ENV
to production
, express.errorHandler
will not be used.