Node.js Tutorial
- Node.js Tutorial
- Install Node.js on Windows
- Install Node.js on Linux/Ubuntu/CentOS
- Node.js First Example
- Node.js Console
- Node.js REPL
- Node.js Package Manager
- Node.js Command Line Options
- Node.js Global Objects
- Node.js OS
- Node.js Timer
- Node.js Errors
- Node.js DNS
- Node.js Net
- Node.js Crypto
- Node.js TLS/SSL
- Node.js Debugger
- Node.js Process
- Node.js Child Process
- Node.js Buffers
- Node.js Streams
- Node.js File System (FS)
- Node.js Path
- Node.js StringDecoder
- Node.js Query String
- Node.js ZLIB
- Node.js Assertion Testing
- Node.js V8
- Node.js Callbacks
- Node.js Events
- Node.js Punycode
- Node.js TTY
- Node.js Web Module
- NestJS
Node.js MySQL
Node.js MongoDB
Nodejs Difference
Node.js MCQ
Node.js Express
Nodejs Interview Questions
Node.js "process.env" Property
The "process.env" functionality is an inbuilt application in the nodejs to display the user environment. It is the programming interface of the nodejs process module to get the user environment as an output.
Syntax
The following syntax uses in the output function to get and display data.
- process.env
- OR
- console.log(process.env);
Return Value: This property shows an object of the user environment.
Examples
Below examples display the operation and the use of the nodejs process.env property.
Example1
- console.log("Node.js process.env Property");
- // Node.js program to operate the process.env Property
- // Use process module of the server
- const process_data = require('process');
- //show the process.env property information
- console.log(process.env);
Output
The image shows the "process.env" property information.
Example 2
The example shows the basic data of the server using the property. We can get server-related information using the process.
- // Node.js program to operate the process.env Property
- console.log("Node.js process.env Property");
- //It contains the processing module
- const process = require('process');
- // Printing process.env property value
- var no_env = 0;
- // Calling process.env with the variable
- var env_var = process.env;
- // Iterating through all returned data
- for (var key in env_var) {
- // Print value
- console.log(key + " :\t\t\t " + env_var[key]);
- no_env++;
- }
- // display count
- console.log("total no of values available = "
- + no_env);
- // Access one by one all the information
- console.log("operating system: " + env_var['OS']);
- console.log("alluserprofile: " + env_var['ALLUSERSPROFILE']);
- console.log("public directory: " + env_var['PUBLIC']);
Output
The image shows the "process.env" property information.
Example 3
The example shows the basic data of the server using the property. Here, we can add and delete new data with the process.env property.
- // Node.js program to operate the process.env Property
- console.log("Node.js process.env Property");
- // it contains the process module
- const process = require('process');
- // Printing process.env property value
- var env_proc = process.env;
- console.log("operating system: " + env_proc.OS);
- console.log("all use r profile: " + env_proc.ALLUSERSPROFILE);
- console.log("public directory: " + env_proc.PUBLIC);
- // Setting new data
- env_proc.getd= "gekcho custom data";
- console.log("stored in env.gekcho: " + env_proc.getd);
- // Delete data
- delete env_proc.getd
- console.log("contain in env.gekcho: " + env_proc.getd);
Output
The image shows the "process.env" property information.
Example 4
The example shows the basic data of the server using the property. We can get the path and port of the process.
- // Node.js program to operate the process.env Property
- console.log("Node.js process.env Property");
- //basic process property
- console.log(process.env);
- //get the path of the process
- const PATH_process = process.env.PATH
- // Calling process.env for the port
- const PORT_process = parseInt(process.env.PORT);
- // Access one by one all the information
- console.log("Process Path: " + PATH_process);
- console.log("Process PORT: " + PORT_process);
Output
The image shows the "process.env" property information.
Conclusion
The nodejs process.env is the environmental variable to get system information. The process detail displays a single keyword or line in the console tab. The method is essential and easy to use for the developer and users.