OSDN Git Service

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