Skip to content
Justice Tech School

Globals and process

process describes the running program: process.argv holds command line arguments, process.env holds environment variables and process.exit ends the program. __dirname gives the current folder in CommonJS.

Example
console.log(process.argv.length >= 2);
console.log(process.env.MY_SETTING ?? "not set");
console.log(typeof process.pid, process.platform.length > 0);
console.log(typeof __dirname);

Result

true
not set
number true
string

Exercise

Read an environment variable.

process..PORT

Quiz Test

Where do command line arguments live?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.