process.argv

An array of the command-line arguments passed when the Node process was launched.

Since Node 0.x Spec ↗

Syntax

process.argv

Returns

string[] — argv[0] is the node binary, argv[1] the script, the rest are user args.

Examples

// node app.js --port 8080
const args = process.argv.slice(2);
console.log(args);
Output
[ '--port', '8080' ]
import { parseArgs } from 'node:util';

const { values } = parseArgs({
  options: { port: { type: 'string', default: '3000' } },
});
console.log(values.port);
Output
3000

Notes

Always `slice(2)` to drop the binary and script paths. For anything beyond trivial flags use `util.parseArgs` instead of hand-parsing.

See also