<

Node.js Process Tutorial

Some Node.js process are id, architecture, platform, version, release, uptime, upu usage etc. Nodejs process used to kill process, set uid, set groups, unmask etc.

The process is a global object, an instance of EventEmitter, can be accessed from anywhere.

Node.js Process Properties



  • arch returns process architecture: 'arm', 'ia32', or 'x64'

  • args returns commands line arguments as an array

  • env returns user environment

  • pid returns process id of the process

  • platform returns platform of the process: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32'

  • release returns the metadata for the current node release

  • version returns the node version

  • versions returns the node version and its dependencies


  • Node.js Process Properties Example



    process.js
    console.log(`Process Architecture: ${process.arch}`);  
    console.log(`Process PID: ${process.pid}`);  
    console.log(`Process Platform: ${process.platform}`);  
    console.log(`Process Version: ${process.version}`);  
    

    Open Node.js command prompt and run the following code:

    node process.js  
    


    Node.js Process Functions



  • cwd() returns path of current working directory

  • hrtime() returns the current high-resolution real time in a [seconds, nanoseconds] array

  • memoryUsage() returns an object having information of memory usage.

  • process.kill(pid[, signal]) is used to kill the given pid.

  • uptime() returns the Node.js process uptime in seconds.


  • Node.js Process Functions Example



    process_function.js
    console.log(`Current directory: ${process.cwd()}`);  
    console.log(`Uptime: ${process.uptime()}`);  
    

    Open Node.js command prompt and run the following code:

    
    node process_function.js  
    
    
    















    © copyright 2017-2022 Completedone pvt ltd.