cheatsheets/nodejs.md

50 lines
1.1 KiB
Markdown
Raw Permalink Normal View History

2013-10-14 02:36:58 +00:00
---
title: Node.js API
2015-11-24 04:48:01 +00:00
category: Node.js
2014-06-07 15:07:14 +00:00
---
2013-05-29 12:19:07 +00:00
### Globals
2013-05-29 12:19:07 +00:00
__filename
__dirname
### exec
var exec = require('child_process').exec,
var child = exec('cat *.js bad_file | wc -l',
function (error, stdout, stderr) {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
if (error !== null) {
console.log('exec error: ' + error);
}
});
### Snippets
2013-05-29 12:19:07 +00:00
info = require('../package.json')
info.version
process.stdout.write(util.inspect(objekt, false, Infinity, true) + '\n');
2013-10-14 01:55:21 +00:00
### Spawn - passthru the in/out
2013-10-14 01:55:21 +00:00
var spawn = require('child_process').spawn;
var proc = spawn(bin, argv, { stdio: 'inherit' });
proc.on('error', function(err) {
if (err.code == "ENOENT") { "does not exist" }
if (err.code == "EACCES") { "not executable" }
});
proc.on('exit', function(code) { ... });
2014-04-28 10:57:58 +00:00
// also { stdio: ['pipe', 'pipe', process.stdout] }
2013-10-14 01:55:21 +00:00
// also { stdio: [process.stdin, process.stderr, process.stdout] }
2014-02-25 10:32:14 +00:00
proc.stdout.on('data', function (data) {
});
proc.stderr.on('data', function (data) {
});
2013-10-14 02:36:58 +00:00
[all]: http://nodejs.org/api/all.html