Tuesday, 29 May 2018

010 Node.js Process

The process object is a global object.process object provides information about the current Node.js process. You can use without using require().

Here are some process properties

arch : Returns a string identifying the operating system CPU architecture 'arm', 'ia32', or 'x64'.
 

args : Returns commands line arguments as an array.

env : Returns an object containing the user environment.

pid : Returns process id(PID) of the process.

platform : Returns a string identifying the operating system platform  'darwin', 'freebsd', 'linux', 'sunos' or 'win32'.

release : Returns the metadata for the current release.


version : Returns the node version string.


versions : Return a object listing the version strings of Node.js and its dependencies.


Example :


console.log(`Process Architecture: ${process.arch}`);
console.log(`Process Arguments: ${process.args}`);
console.log(`Process ID: ${process.pid}`);
console.log(`Process Plat Form: ${process.platform}`);
console.log(`Process Release: ${process.release}`);
console.log(`Process Version: ${process.version}`);
console.log(`Process Versions: ${process.versions}`); 


Output :















Here are some process Methods

cwd :Method returns current working directory of the Node.js process.

hrtime : Returns the current high-resolution real time in a [seconds, nanoseconds] array.


memoryUsage : Method returns an object describing information of memory usage.


process.kill :
Method is used to kill process by  sends the signal to the process identified by pid.

uptime : Returns the Node.js process uptime in seconds  current Node.js process has been running.

exit : Ends the process with the specified code. If omitted, exit uses the 'success' code 0.

setgroups : method sets the supplementary group IDs for the Node.js process.

nextTick : method adds the callback to the "next tick queue"
.

Example :


console.log(`Starting directory: ${process.cwd()}`);
console.log(`Starting directory: ${process.hrtime()}`);
console.log(`Starting directory: ${process.memoryUsage()}`);
console.log(`Starting directory: ${process.uptime()}`);


Output :







Here are some process event


beforeExit : Fires when Node.js empties its event loop and has no additional work to schedule.

exit : Fires when the Node.js process is about to exit.

uncaughtException : Fires when an uncaught JavaScript exception bubbles all the way back to the event loop.

No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...