Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save GuillermoPena/8bab46067306c06448d1 to your computer and use it in GitHub Desktop.
Save GuillermoPena/8bab46067306c06448d1 to your computer and use it in GitHub Desktop.
NodeJS - STDIO : Inserting arguments by console
// 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