How to use the out function from yargs

Find comprehensive JavaScript yargs.out code examples handpicked from public code repositorys.

yargs.out is a method used to customize where yargs output is displayed.

20
21
22
23
24
25
26
27
28
29
30
31
process.on("unhandledRejection", err => {
  throw err;
});


const source = (argv.source === undefined) ? paths.appSrc : argv.source;
const out = (argv.out === undefined) ? paths.appDocs : argv.out;
const json = (argv.json === undefined) ? paths.appJsonDocs : argv.json;


const baseUrlOptions = (argv.baseUrl === undefined) ? [] : ["--baseUrl", argv.baseUrl];
const includeOptions = (argv.includes === undefined) ? [] : ["--includes", argv.includes];
fork icon193
star icon513
watch icon0

+ 4 other calls in file

32
33
34
35
36
37
38
39
40
41
    }
}

// check if we were passed a custom out directory, pass it along if so
if (argv.out) {
    options.out = argv.out
}

// call the packager to produce the executable
packager(options)
fork icon31
star icon63
watch icon3

How does yargs.out work?

yargs.out is a property in the Yargs module that sets the output stream for logs and errors. It is used to redirect the output to a different stream than the default one (process.stdout). By default, it is set to process.stdout, but it can be changed to any other Writable stream.

Ai Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const fs = require("fs");
const yargs = require("yargs");

const logs = fs.createWriteStream("logs.txt");

yargs
  .usage("Usage: $0 [options]")
  .command(
    "start",
    "Start the server",
    () => {},
    (argv) => {
      yargs.out(logs); // use logs file as output stream
      console.log("Server started!");
    }
  )
  .parse();

In this example, yargs.out(logs) sets the output stream to the logs file for the start command, so any logs generated by Yargs or the application will be written to this file instead of the default output stream (usually the console).

Other functions in yargs

Sorted by popularity

function icon

yargs.argv is the most popular function in yargs (1012 examples)