OSDN Git Service

Regular updates
[twpd/master.git] / nodejs-process.md
1 ---
2 title: process
3 category: Node.js
4 ---
5
6 ### Streams
7
8     process.stdout.write('...');
9     process.stderr.write('...');
10
11     function stdin(fn) {
12       var data = '';
13
14       process.stdin.setEncoding('utf8');
15       process.stdin.on('readable', function() {
16         var chunk = process.stdin.read();
17         if (chunk !== null) data += chunk;
18       });
19
20       process.stdin.on('end', function() {
21         fn(null, data);
22       });
23     }
24
25 ### stuff
26
27     process.argv; //=> ['node', 'file.js', 'one', 'two']
28     process.env; //=> {TERM: 'screen-256color', SHELL: '/bin/bash', ...}
29
30     process.exit();
31     process.exit(1);
32
33 ### Directories
34     
35     process.cwd(); //=> "/tmp"
36     process.chdir('dir');
37
38 ### References
39
40 - http://nodejs.org/api/process.html