Book Image

PhantomJS Cookbook

By : Rob Friesel
Book Image

PhantomJS Cookbook

By: Rob Friesel

Overview of this book

Table of Contents (15 chapters)
PhantomJS Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Inspecting system environment variables


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.

Getting ready

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.

How to do it…

Prepare the host environment by setting the BOOK_TITLE variable:

Platform

Set variable by

Windows

SET BOOK_TITLE=PhantomJS Cookbook

Mac OS X

export BOOK_TITLE="PhantomJS Cookbook"

Linux

export BOOK_TITLE="PhantomJS Cookbook"

Consider the following script:

var env  = require('system').env,
    prop = 'BOOK_TITLE';

var keys = Object.keys(env).filter(function(k) {
  return k...