SHARE
TWEET

Untitled

a guest Oct 14th, 2019 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // helper method to search for an argument passed to node app
  2. // rules: arguments must be preceded with '--' characters to be recognized as parameter
  3. // example: node apps.js --port=2134 host=2312 --force ('host' won't be recognized, 'force'
  4. //          will be recognized and returns 'true')
  5.  
  6. const _findargs = (name) => {
  7.   const args = process.argv.slice(2); const param = args.find((el) => el.startsWith(`--${name}`))
  8.   if (!param) return null
  9.   if (param.indexOf('=') === -1) return 'true'
  10.   return param.replace(`--${name}=`, '')
  11. }
  12.  
  13. // example usages
  14. server.start({
  15.   host: _findargs('port') || DEFAULT_PORT,
  16.   port: _findargs('host') || DEFAULT_HOST
  17. })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top