
Now once again using the environment: const connection = new Connection(_CONNECTION_STRING)
#Npm config set environment variable code
This makes the code more tedious to test because more code execution branches exist, and it is also an eyesore.
#Npm config set environment variable series
Or, we’d have to modify our code into a series of branch conditions: let connectionString if (runningLocally()) const connection = new Connection(connectionString) However, when we deploy it to a server in production, we might possibly need to link it to a remote server, say 54.32.1.0:3306.Īssuming the non-use of the environment, we’d need to either make sure a database is available on the same machine as the application so we can call 127.0.0.1:3306, which results in tight coupling, low availability and no scalability (we can only deploy one instance of the application since we’re depending on that one database).

If we require a database in development, we spin up an instance of it and we link to it via a connection string - something like 127.0.0.1:3306. When we write our code, we can never be sure where our application can be deployed. Ultimately, if an application is not deployed, no one can use it and it serves no purpose.

Why environment is importantĪn application needs to be deployed in order for it to be useful, and this can be anything from code that creates a simple website to complex APIs that engage in intensive computations. For example, if the system has a PATH variable set, this will be made accessible to you through which you can use to check where binaries are located and make external calls to them if required.

The process.env global variable is injected by the Node at runtime for your application to use and it represents the state of the system environment your application is in when it starts. Why not just specify the port as 3000 instead of typing sixteen characters? What it is So you’ve gotten past your first few tutorials in Node.js and you’ve probably seen the line app.listen() or something to that effect. Process.env: What it is and why/when/how to use it effectively
