This recipe expands on the system
module, demonstrating how to use its env
property to obtain the values of variables set in the host environment.
To run this recipe, we will need a script that expects to retrieve values from variables set in the host environment; we should set those variables ahead of time for the sake of demonstration.
The script in this recipe is available in the downloadable code repository as recipe07.js
under chapter02
. If we run the provided example script, we must change to the root directory for the book's sample code.
Prepare the host environment by setting the BOOK_TITLE
variable:
Platform |
Set variable by |
---|---|
Windows |
|
Mac OS X |
|
Linux |
|
Consider the following script:
var env = require('system').env, prop = 'BOOK_TITLE'; var keys = Object.keys(env).filter(function(k) { return k...