added script to node-local testing for running test.js via the action… (#38)

* added script to node-local testing for running test.js via the action container itself, so that npm libraries can be tested more simply
* avoiding merge conflict; JSON output was added by another PR
* fixing multiple params
diff --git a/node-local/README.md b/node-local/README.md
index 1ec15b5..f59190e 100644
--- a/node-local/README.md
+++ b/node-local/README.md
@@ -24,4 +24,20 @@
 
 If you intend to post-process the result, for instance with `jq`, add the parameter `--json`,
 which will make sure `test.js` returns well-formed JSON. The default is off, which means you
-will get a slightly more readable output.
\ No newline at end of file
+will get a slightly more readable output.
+
+## using npm libraries
+
+If your action uses npm libraries, you may have trouble running it locally without creating a special environment just for it to run.
+
+In this case you can run the docker image that open whisk uses to launch your action, along with its preinstalled libraries:
+
+```bash
+./runtest.sh --debug --action ./path-to-function.js --param name=value --param othername=othervalue
+```
+
+Usage:
+* --debug : enable request debugging (by adding NODE_DEBUG=request)
+* --action : action js file you are trying to test 
+* --param : parameter to pass to main (multiple allowed)
+* --image : the action image used to run node (default is openwhisk/nodejs6action:latest)
diff --git a/node-local/runtest.sh b/node-local/runtest.sh
new file mode 100755
index 0000000..444a740
--- /dev/null
+++ b/node-local/runtest.sh
@@ -0,0 +1,57 @@
+#!/bin/bash
+
+abs_path()
+{
+    pushd $(dirname "$1") > /dev/null
+    echo $(pwd)/$(basename "$1")
+    popd > /dev/null
+
+}
+
+this_dir=$(dirname "$(abs_path "$0")")
+action_executor="$this_dir/test.js"
+action_image="openwhisk/nodejs6action:latest"
+debug_env="debug_disabled"
+
+
+while [[ $# -gt 1 ]]
+do
+key="$1"
+
+case $key in
+    --action)
+    action="$(abs_path "$2")"
+    shift # past argument
+    ;;
+    --param)
+    params+=" $2"
+    shift # past argument
+    ;;
+    --image)
+    actionimage="$2"
+    shift # past argument
+    ;;
+    --debug)
+    debug_env="NODE_DEBUG=request"
+    ;;
+    *)
+            # unknown option
+    ;;
+esac
+shift # past argument or value
+done
+
+echo "#######################################################"
+echo "Testing action $action using image $action_image"
+echo "#######################################################"
+
+
+
+docker_cmd="docker run --name=\"actiontest\" --rm -it \
+    -e \"$debug_env\" \
+    -v \"$action_executor:/nodejsAction/testexecutor.js\" \
+    -v \"$action:/nodejsAction/testaction.js\" \
+    $action_image node testexecutor.js ./testaction.js $params"
+
+#using eval here because $params may have multiple space separate values, which need to be passed as separate args
+eval "$docker_cmd"
diff --git a/node-local/test.js b/node-local/test.js
index 63f4bda..416f368 100644
--- a/node-local/test.js
+++ b/node-local/test.js
@@ -77,12 +77,11 @@
   }
   
   const imports = require(action);
-  
+
   //support a non-exported main function as a fallback
   const mainfunct = imports.main ? imports.main : fallback(action);
   
   let result = mainfunct(params);
-  
   if (result.then) {
     Promise.resolve(result)
       .then(result => console.log(outputJSON ? JSON.stringify(result) : result))
@@ -90,4 +89,10 @@
   } else {
     console.log(outputJSON ? JSON.stringify(result) : result);
   }
-}
\ No newline at end of file
+}
+
+//allow ctrl-c to exit...
+process.on('SIGINT', function() {
+  console.log("exiting...");
+  process.exit();
+});
\ No newline at end of file