Created
May 28, 2014 09:52
-
-
Save GuillermoPena/8bab46067306c06448d1 to your computer and use it in GitHub Desktop.
NodeJS - STDIO : Inserting arguments by console
This file contains 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
// More info here: http://sgmonda.github.io/stdio/ | |
var stdio = require('stdio') | |
var opts = stdio.getopt({ | |
'name': { key: 'n', description: 'Name', args: 1, mandatory: true }, | |
'surnames': { key: 's', description: 'Surnames', args: 2 }, | |
'age': { key: 'a', description: 'Age: ', args: 1 } | |
}) | |
console.log( 'Your full name is ' + opts.name | |
+ ' ' + opts.surnames.join(' ') | |
+ ' and your age is ' + opts.age) | |
// To insert arguments by console without stdio module use process.arg | |
// process.argv[0] // Script name and all arguments | |
// process.argv[1] // Script name (Probably 'node') | |
// process.argv[2] // First argument | |
// process.argv[3] // Second argument ... etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment