OSDN Git Service

Regular updates
[twpd/master.git] / nodejs.md
1 ---
2 title: Node.js API
3 category: Node.js
4 ---
5
6 ## Globals
7
8     __filename
9     __dirname
10
11 ### exec
12
13     var exec = require('child_process').exec,
14
15     var child = exec('cat *.js bad_file | wc -l',
16       function (error, stdout, stderr) {
17         console.log('stdout: ' + stdout);
18         console.log('stderr: ' + stderr);
19         if (error !== null) {
20           console.log('exec error: ' + error);
21         }
22     });
23
24 ## Snippets
25
26     info = require('../package.json')
27     info.version
28
29     process.stdout.write(util.inspect(objekt, false, Infinity, true) + '\n');
30
31 ## Spawn - passthru the in/out
32
33     var spawn = require('child_process').spawn;
34     var proc = spawn(bin, argv, { stdio: 'inherit' });
35     proc.on('error', function(err) {
36       if (err.code == "ENOENT") { "does not exist" }
37       if (err.code == "EACCES") { "not executable" }
38     });
39     proc.on('exit', function(code) { ... });
40
41     // also { stdio: ['pipe', 'pipe', process.stdout] }
42     // also { stdio: [process.stdin, process.stderr, process.stdout] }
43
44     proc.stdout.on('data', function (data) {
45     });
46     proc.stderr.on('data', function (data) {
47     });
48
49 [all]: http://nodejs.org/api/all.html