Search code examples
javascriptnode.jsyargs

Yargs.argv is always [object Object]


Ubuntu 16.04. I'm doing a node.js course on Udemy. I tried it with the exact version the instructor was using, then I upgraded to the latest(11.0.0). Both gave the same output.

const yargs = require('yargs');

var argv = yargs.argv;

console.log("yargs : " + argv);

I run it on the console with

node app.js jdskl jkdlsfj

console output is

yargs : [object Object]

As I understand it, it should have my args in there.


Solution

  • Try console.log("yargs : ", argv);

    The + concatenates the string, the , passes argv as a separate argument to console log which should trigger a separate log format


    The other option is: console.log("yargs : " + JSON.stringify(argv)); as this will serialize your object into a JSON string representation