DEV Community

kim
kim

Posted on

1

Node.Js Api Cheat Sheet

Spawn - passthru the in/out

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) { ... });

// also { stdio: ['pipe', 'pipe', process.stdout] }
// also { stdio: [process.stdin, process.stderr, process.stdout] }

proc.stdout.on('data', function (data) {
});
proc.stderr.on('data', function (data) {
});

Enter fullscreen mode Exit fullscreen mode




Snippets


info = require('../package.json')
info.version

process.stdout.write(util.inspect(objekt, false, Infinity, true) + '\n');

Enter fullscreen mode Exit fullscreen mode




[Globals] 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);
}
});

Enter fullscreen mode Exit fullscreen mode




Globals


__filename
__dirname
Enter fullscreen mode Exit fullscreen mode




Reference

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay