Skip to main content
Module

x/yargs/example/line_count.js

yargs the modern, pirate-themed successor to optimist.
Go to Latest
File
#!/usr/bin/env nodevar argv = require('yargs/yargs')(process.argv.slice(2)) .usage('Count the lines in a file.\nUsage: $0') .demand('f') .alias('f', 'file') .describe('f', 'Load a file') .argv;
var fs = require('fs');var s = fs.createReadStream(argv.file);
var lines = 0;s.on('data', function (buf) { lines += buf.toString().match(/\n/g).length;});
s.on('end', function () { console.log(lines);});