SkillByAIOpen interactive version →

Lesson 24 / 30

The process Object

Read command-line arguments and runtime details with process.argv, process.cwd and process.platform.

Command-line arguments

process.argv is an array — the first two entries are the node binary and script path, the rest are your arguments.

// greet.js
const name = process.argv[2] || "stranger";
console.log(`Hello, ${name}!`);

// $ node greet.js Ada
// Hello, Ada!

cwd & platform

Useful runtime details without any import.

console.log(process.cwd());       // current working directory
console.log(process.platform);    // 'linux', 'darwin', 'win32'
console.log(process.version);     // v20.11.0