-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stdlib: cache environment variables (#454)
Removes the 'log' export from 'insight'. Accessing process.env.XXX is relatively slow in Node.js. Benchmark of a plain object property access and accessing process.env.NODE_ENV: ``` property access 500000000 iterations 0 ns/op process.env access 5000000 iterations 246 ns/op ``` See this thread nodejs/node#3104 for some more context
- Loading branch information
Showing
26 changed files
with
239 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Cached process.env | ||
*/ | ||
export let environment = {}; | ||
|
||
/** | ||
* Repopulate the cached environment copy. | ||
* This should only be necessary when you or a sub package mutates the environment. | ||
* The `mainFn` / `mainTestFn` / `mainBenchFn` / ... will call this function by default | ||
* after loading your `.env` file. | ||
* | ||
* Accessing process.env.XXX is relatively in Node.js. | ||
* Benchmark of a plain object property access and accessing process.env.NODE_ENV: | ||
* | ||
* property access 500000000 iterations 0 ns/op | ||
* process.env access 5000000 iterations 246 ns/op | ||
* | ||
* See this thread: https://github.com/nodejs/node/issues/3104 | ||
*/ | ||
export function refreshEnvironmentCache() { | ||
environment = JSON.parse(JSON.stringify(process.env)); | ||
} | ||
|
||
/** | ||
* @returns {boolean} | ||
*/ | ||
export function isProduction() { | ||
return environment.NODE_ENV === "production"; | ||
} | ||
|
||
/** | ||
* @returns {boolean} | ||
*/ | ||
export function isStaging() { | ||
return ( | ||
environment.NODE_ENV !== "production" || environment.IS_STAGING === "true" | ||
); | ||
} |
Oops, something went wrong.