Created
February 20, 2019 14:58
-
-
Save questsin/64f03e281d24265723461c58f87f1243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
//chmod u+x yourscript | |
var express = require('express'); | |
var prompt = require('prompt'); | |
//cli | |
var fs = require('fs'); | |
var stdin = process.stdin; | |
var stdout = process.stdout; | |
var args = process.argv.slice(2); | |
//receiving piped data | |
process.stdin.resume(); | |
process.stdin.setEncoding('utf8'); | |
process.stdin.on('data', function(data) { | |
process.stdout.write(data); | |
}); | |
//Signal handleing | |
process.on('SIGINT', () => { | |
console.log('Received SIGINT. Press Control-D to exit.'); | |
}); | |
//prompts | |
prompt.start(); | |
prompt.get(['username', 'email'], function (err, result) { | |
if (err) { return onErr(err); } | |
console.log('Command-line input received:'); | |
console.log(' Username: ' + result.username); | |
console.log(' Email: ' + result.email); | |
}); | |
function onErr(err) { | |
console.log(err); | |
return 1; | |
} | |
//exiting | |
function done(err) { | |
console.log('exit.'); | |
//error handling | |
if (err) { | |
process.exit(1); | |
} else { | |
process.exit(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment