On this page

    P

    process.argv

    History
    Type:string[]

    The process.argv property returns an array containing the command-line arguments passed when the Node.js process was launched. The first element will be process.execPath. See process.argv0 if access to the original value of argv[0] is needed. If a program entry point was provided, the second element will be the absolute path to it. The remaining elements are additional command-line arguments.

    For example, assuming the following script for process-args.js:

    import { argv } from 'node:process';
    
    // print process.argv
    argv.forEach((val, index) => {
      console.log(`${index}: ${val}`);
    });
    const { argv } = require('node:process');
    
    // print process.argv
    argv.forEach((val, index) => {
      console.log(`${index}: ${val}`);
    });

    Launching the Node.js process as:

    Would generate the output:

    0: /usr/local/bin/node
    1: /Users/mjr/work/node/process-args.js
    2: one
    3: two=three
    4: four