Thursday, February 14, 2013

NodeJS Module - optimist

Hello Guys ! here is my next post on NodeJS

In this tutorial , i will show you guys an extremely useful module
called 'optimist'

optimist module helps to parse incoming flags and options by creating a command-line script
ordering of flags does not matter

You can use different kinds of arguments
1)short arguments
2)long arguments
3)boolean arguments
4)non-hypenated options

Here is my sample code :-


I have printed the values of short argument , long argument , boolean argument , and nonhypenated arguement
I got the following output



'optimist' module also provides different functions like

.usage and .demand --> they are used to let the user type the exact command in the command prompt otherwise print the usage of the command

here is sample code :-






usage function says that if the required option is not printed , the specified statement will be printed

I got the following output


 
 .default --> it sets some default values to the options

here is sample code :- 



and the output

hope this post helps you !!!

Thanks !!