NODE-FLAG
Access to Node.js Command Line Flags
Require Node 4+
How To:
install the module:
$ npm install node-flag
import it:
const nodeFlags =
use it:
// check if flag is set or notconsole //returns boolean value // get all command line flagsconsole // get single (or all) command line flagconsole // if you don't set the flag title; all flags will be retured.
example:
# in Terminal: $ node app.js --host 127.0.0.1 --port 3000# OR $ node app.js -h 127.0.0.1 -p 3000 # NOTE: # if you use single hyphen (-) as flag title prefix # you can only set 1 character length flag title like -h but # if you want to set more than 1 character length flag title # you have to set double hyphens (--) as flag title prefix like --host
// in your application: 'use strict' const nodeFlags = //check if a specific flag is set or notconsole //returns boolean value // get all command line flagsconsole/* result: { host: '127.0.0.1', port: '3000' } OR: { h: '127.0.0.1', p: '3000' }*/ // get single command line flagconsole
Only Get Valid/Required Flags:
if you want to filter getAll()
or get()
results with your valid/required flags just use validFlags()
method before of them.
nodeFlags//OR:nodeFlags
Assigning Flag Titles:
$ node app.js -h 127.0.0.1 -p 3000
nodeFlags console // result: '127.0.0.1'
THIS IS JUST A SIMPLE WEEKEND PROJECT!