Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // helper method to search for an argument passed to node app
- // rules: arguments must be preceded with '--' characters to be recognized as parameter
- // example: node apps.js --port=2134 host=2312 --force ('host' won't be recognized, 'force'
- // will be recognized and returns 'true')
- const _findargs = (name) => {
- const args = process.argv.slice(2); const param = args.find((el) => el.startsWith(`--${name}`))
- if (!param) return null
- if (param.indexOf('=') === -1) return 'true'
- return param.replace(`--${name}=`, '')
- }
- // example usages
- server.start({
- host: _findargs('port') || DEFAULT_PORT,
- port: _findargs('host') || DEFAULT_HOST
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement