AI Workshop: learn to build apps with AI →
Core Concepts: Node, the difference between development and production

Join the AI Workshop and learn to build real-world apps with AI. A hands-on, practical program to level up your skills.


You can have different configurations for production and development environments.

Node assumes it is running in a development environment unless told otherwise. Set the NODE_ENV=production environment variable to indicate production.

You can set it by running

export NODE_ENV=production

in the shell. To make it persistent, add it to your shell configuration file (e.g. .bash_profile for Bash).

You can also apply the environment variable by prepending it to your application initialization command:

NODE_ENV=production node app.js

This environment variable is a convention that is widely used in external libraries as well.

Setting the environment to production generally ensures that

  • logging is kept to a minimum, essential level
  • more caching levels take place to optimize performance

For example Pug, the templating library used by Express, compiles in debug mode if NODE_ENV is not set to production. Express views are compiled in every request in development mode, while in production they are cached. There are many more examples.

Express provides configuration hooks specific to the environment, which are automatically called based on the NODE_ENV variable value:

app.configure('development', () => {
  //...
})
app.configure('production', () => {
  //...
})
app.configure('production', 'staging', () => {
  //...
})

For example, you can use this to set different error handlers for different modes:

app.configure('development', () => {
  app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
})

app.configure('production', () => {
  app.use(express.errorHandler())
})

Lessons in this unit:

0: Introduction
1: The Node Core Modules
2: Differences between Node and the Browser
3: ▶︎ Node, the difference between development and production
4: The Node.js Event Loop
5: A brief history of Node.js
6: Understanding process.nextTick()
7: Understanding setImmediate()
8: How to check the current Node.js version at runtime
9: Why should you use Node.js in your next project?
10: Introduction to Node.js