0

I'm learning nodejs, when I work with tutorial like expressjs and krakenjs, I saw these terms many times:

Production and Development Environment

Production and Development Environment

My understand is, those are config for production and development time, but why are they in same code? If the app/website is published, does it still have the development config inside?

I still don't get the idea...

Sang Dang
  • 501
  • 1
  • 11
  • 26
  • 1
    I'm not totally sure what you're asking. That image you've included basically says "You can include two config files in your project, `app.json` and `app-development.json`. When you want to change from one to the other, restart your service with a different `NODE_ENV` environment value." See also [What is NODE_ENV in Express?](http://stackoverflow.com/q/16978256/710446) As for "does it still have the `development` config inside?" -- it *can*, but obviously it won't do anything if you're using the correct NODE_ENV value in production. – apsillers Apr 13 '16 at 13:11
  • Example, when I install Ghost blog, I saw it again in config.js https://github.com/TryGhost/Ghost/blob/master/config.example.js `config = { // ### Production production: { ... } // ### Development **(default)** development: { ... }` – Sang Dang Apr 13 '16 at 13:31

1 Answers1

1

You are correct that they are configuration files that are used either when doing development on your own box or when the code is running in production. You're development config file may contain a connection string to a database running on your development machine whereas the production connection string will probably point to a big, fast server with production data on it.

And yes, it's fine to have both files in your code at the same time, even when it's running in production as long as you make sure the system is using the correct one. You tell the system which one to use by setting the NODE_ENV environment variable to either dev or prod. Kraken will look at the value inside NODE_ENV and use the appropriate config file. This is a pretty common thing to do in node.

d512
  • 32,267
  • 28
  • 81
  • 107
  • Thank you, so I understood it right. But I still have a little confuse here. As we have only 1 source, so what if we work in development, change the code, the production site will be broken? – Sang Dang Apr 13 '16 at 16:04
  • 1
    Well if you are doing development work it should be on a different box that production. You don't ever want to work directly on a production box. So you would get a separate copy of the code to modify. This is done in your development environment (where `NODE_ENV='dev'`). After you make your changes and test them, then you deploy those changes to your production environment (where `NODE_ENV='prod'`). – d512 Apr 13 '16 at 16:16
  • 1
    Possibly. You can use git to do deployments. Heroku works that way. The point is that you have one or more computers running your code that your customers use. This is your production environment. Then you have one or more computers with the code that you use to do development. This is your development environment. The should be kept completely separate and should not interfere with each other in any way. The configuration file you mentioned in your question is one way that you can help the code know if the computer it's running on is a development or production computer. – d512 Apr 13 '16 at 18:18
  • I don't know how to express my appreciation to you. Thank you so much. – Sang Dang Apr 13 '16 at 18:36