Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  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. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement