Development vs Production

Updated on Oct 4, 2023

Now that we know what Node.js is and what it can be used for, we should talk about some core elements of the environment itself. And, speaking of environments, we will first examine the two modes the environment can be in: development and production.

The naming is very intuitive since the two environments serve either a developmental or production purpose. As we mentioned in the previous part, an environment in the context of programming is the configuration of a system that houses all the necessary tools and functionalities a developer needs to create applications. Typically, every application starts in a development environment and then transitions to the production environment once finished. That is a broad generalization because every developer or company will have their own methodology. Still, typically, development is the start, and production is the finish. Let’s break them both down and explain what they do.

Development Environment

Whether writing a new application or working on an existing one, you will be in a development environment. It can be a separate Node.js instance on the server your application is running or a local instance on your personal computer. The same goes for the database you are using for your application: it is different from the one the live application is using if you are working on a live application. If you try to edit the code of an application already online without having a separate development environment, that can cause many issues for the users currently on the application.

If you are just starting out, though, you don’t need to worry about breaking an existing application. Still, you should definitely keep that development environment for future edits and additions to your application when it goes live. The whole purpose of this exercise is to prevent corrupting the data of your live application by working directly on it without first testing it in a separate environment.

To summarize, a development environment is a testing ground. Within it, you can create anew or edit without worrying about affecting anything else.

Production Environment

When your application goes live, it also goes in a production environment. The actual name of the production environment differs from company to company or developer to developer. Still, it is the final stage of development for your application. It is finished and ready to be unleashed online for users to experience.

At this point of the production process, you should have ironed out any errors, and the application should be fully functional. If it is not, you have the development environment to test in. As we suggested above, keeping your production and development environments separate is a good idea. That way, any changes you make will not affect the live application. Aside from that, the two environments have only a couple of differences.

Logging (errors or events in general) is kept to a minimum in production. The  system will note down only the most essential errors or messages;

Caching becomes more active to ensure the application is quicker and performs better.

How to Switch Between the Two

By default, Node.js always assumes you are in the development environment. That is a handy feature to have, as it can eliminate confusion. As for switching between the two environments, there are a couple of ways, and each of them changes the NODE_ENV= environment variable to production. 

  • Shell (Command Line) - You can run the command below in the shell or add it to your shell configuration file (.bash_profile, for example, but omit export). That way, the production environment will persist between system restarts:
    • export NODE_ENV=production
  • Initialization Command - You can also prepend the command from above to the initialization command of your application. For instance: 
    • NODE_ENV=production node app.js

And that is it. That is how you switch from development to production and vice versa. Make sure to utilize this functionality, as it can save you a lot of time and effort from troubleshooting where something went wrong after that last update on your live application.

On this page...

    Node.js Hosting

    • Multiple Node Versions
    • 24/7 Node.js Support
    • Free Domain Transfer
    • Hack-free Protection
    • Fast SSD Storage
    • Free Node.js Transfer
    • Free Cloudflare CDN
    • Immediate Activation
    View More