Tuesday, 2 October 2018

Node.js: Process object

‘process’ object is available globally, it is used to get information about current process instance.

By using process object, you can perform many things like
a.   Exit the process
b.   Read the command line arguments passed to the node.js application
c.   Get the absolute pathname of the executable that started the Node.js process.
d.   Get the memory usage of the process
e.   Get the process id of the process
f.    Process id of the current process parent

Get command line arguments passed to node.js process
‘process.argv’ method returns an array that contains the command line arguments passed to node.js process.

HelloWorld.js
console.log(process.argv);


C:\Users\krishna\Documents\Study\nodejs\examples>node HelloWorld.js
[ 'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\krishna\\Documents\\Study\\nodejs\\examples\\HelloWorld.js' ]

Try to pass some command line arguments and check the output.

C:\Users\krishna\Documents\Study\nodejs\examples>node HelloWorld.js Hello How Are you
[ 'C:\\Program Files\\nodejs\\node.exe',
  'C:\\Users\\krishna\\Documents\\Study\\nodejs\\examples\\HelloWorld.js',
  'Hello',
  'How',
  'Are',
  'you' ]



Previous                                                 Next                                                 Home

No comments:

Post a Comment