process.argv
noun
say it: “PRAH-ses dot ARG-vee” /ˈprɑsɛs dɑt ˈɑrɡvi/
An array in Node that holds the words used to start a program, so a script can read what the user typed after its name.
What is process.argv?
process.argv is an array of the words that started your Node program: Node's own path, the script's path, then every word typed after them. process.argv.slice(2) gives the words the user typed.
// node tip.js 42.50 18
const [bill, percent] = process.argv.slice(2);
console.log((Number(bill) * Number(percent)) / 100); // 7.65
In a sentence
- “Skip the first two items of process.argv: they are Node's path and the script's path.”
- “The tip calculator reads the bill and the percent from process.argv.”
Level: Apprentice · More Node.js terms at this level
Updated