DEV Community

Discussion on: Pass arguments from the command line to a Node script

Collapse
 
sugoidesune profile image
Timar
var envs = {  }

process.argv.slice(2).forEach(arg=>{
    var [key,value] =arg.split("=")
    envs[key] = value || true
})

console.log(envs)

>>: node app.js user=john useProduction
>>{
user: 'john',
useProduction: true
}