-
Notifications
You must be signed in to change notification settings - Fork 1
/
1.js
executable file
·37 lines (33 loc) · 1.1 KB
/
1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//#!/usr/bin/env node
//console.log("Hello World");
//process.stdout.write("Hello World!");
function printHelp(){
console.log("1.js (c) softhinkers.com");
console.log("");
console.log("usage:");
console.log("--help print this help");
//console.log("--name say hello to {NAME}");
console.log("--file={NAME} read the file of {NAME} and output");
console.log("");
}
//var args = require("minimist")(process.argv.slice(2),{ string: "name" });
var args = require("minimist")(process.argv.slice(2),{ string: "file" });
//var name = process.argv[2];
//if(args.help || !args.name){
if(args.help || !args.file){
printHelp();
process.exit(1);
}
//var name = args.name;
//console.log("Hello " + name);
var hello = require("./helloworld.js");
//var contents = hello.say(args.file); //for synchronous call
var contents = hello.say(args.file, function(err ,contents){ //error first callback syntax
if(err){
console.error("Error: "+ err);
}else{
console.log(contents.toString());
}
});
//console.log(contents);//array of buffers
//console.log(contents.toString()); //for synchronous call