Skip to content

Commit 743874e

Browse files
committed
usage
1 parent 7e17a24 commit 743874e

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,72 @@ The diagram below should conceptually give you an idea of what this module does.
1616
**The local user that the node process runs as should have virtually zero rights! Also be sure to properly configure a restricted UID/GID when instatiating a new instance of this**
1717

1818
![Alt text](/diagram.png "Diagram1")
19+
20+
### Usage
21+
22+
Its highly recommended you check out the unit-tests for some examples in addition to the below:
23+
24+
```
25+
var Promise = require('promise');
26+
var StatefulProcessCommandProxy = require("stateful-process-command-proxy");
27+
28+
var statefulProcessCommandProxy = new StatefulProcessCommandProxy(
29+
{
30+
name: "test",
31+
max: 1,
32+
min: 1,
33+
idleTimeoutMillis: 10000,
34+
35+
logFunction: function(severity,origin,msg) {
36+
console.log(severity.toUpperCase() + " " +origin+" "+ msg);
37+
},
38+
39+
processCommand: '/bin/bash',
40+
processArgs: ['-s'],
41+
processRetainMaxCmdHistory : 10,
42+
43+
processInvalidateOnRegex :
44+
{
45+
'any':['.*error.*'],
46+
'stdout':['.*error.*'],
47+
'stderr':['.*error.*']
48+
},
49+
50+
processCwd : './',
51+
processEnvMap : {"testVar1":"value1"},
52+
processUid : null,
53+
processGid : null,
54+
55+
initCommands: [ 'echo Hellow World' ],
56+
57+
validateFunction: function(processProxy) {
58+
return processProxy.isValid();
59+
},
60+
61+
preDestroyCommands: [ 'echo Goodbye!' ]
62+
});
63+
64+
// set a var in the shell
65+
statefulProcessCommandProxy.executeCommand('MY_VARIABLE=test1')
66+
.then(function(cmdResult) {
67+
console.log("Stdout: " + cmdResult.stdout);
68+
console.log("Stderr: " + cmdResult.stderr);
69+
}).catch(function(error) {
70+
console.log("Error: " + error);
71+
});
72+
73+
// echo it back
74+
statefulProcessCommandProxy.executeCommand('echo $MY_VARIABLE')
75+
.then(function(cmdResult) {
76+
console.log("Stdout: " + cmdResult.stdout);
77+
console.log("Stderr: " + cmdResult.stderr
78+
}).catch(function(error) {
79+
console.log("Error: " + error);
80+
});
81+
82+
setTimeout(function() {
83+
statefulProcessCommandProxy.shutdown();
84+
},5000);
85+
```
86+
87+

0 commit comments

Comments
 (0)