gasilmystery.blogg.se

Nodejs process
Nodejs process









nodejs process

Returns the metadata for the current node release Returns platform of the process: 'darwin', 'freebsd', 'linux', 'sunos' or 'win32' Returns commands line arguments as an array Returns process architecture: 'arm', 'ia32', or '圆4'

nodejs process

Node.js Process PropertiesĪ list of commonly used Node.js process properties are given below. The process is a global object, an instance of EventEmitter, can be accessed from anywhere. It can also be used to kill process, set uid, set groups, unmask etc. Node.js is a single thread provides the facility to get process information such as process id, architecture, platform, version, release, uptime, upu usage etc. Because of process.exit command in handler, the process exits. Press Ctrl+C, the result is that ‘SIGINT’ event is raised to node application and is captured in handler. This will be a continuous process without any exit criteria because of setInterval. Running the ‘node index.js’ should display the content of the file.Īnother interesting thing about Node.js is that when it is done or doesn’t have anything left to do, then it will exit out of the process. var fs = require('fs')įs.createReadStream(_filename).pipe(process.stdout) For example, replace the content of index.js with the below code. Infact, the console.log is internally doing (msg + ‘\n’).Ĭonsole.log(‘Hello world’) is the same as (‘Hello world’ + ‘\n’).įiles can be read as stream and we can pipe this to process.stdout. Now, let’s pass in some other parameters and you should see the parameters being displayed say ‘node index.js test’.Īlso note that process has ‘process.stdout’ and ‘process.stderr’ which helps us to send a message to the standard output channel and standard error channel if there is any error.

nodejs process

On pressing Enter, the following output should be provided: [ Process object has a property ‘argv’ which is an array containing the properties passed to node process.Ĭreate a simple index.js file and lets console.log the process.argv It can also be explicitly accessed using module global i.e. ‘process’ object is a global which is an instance of EventEmitter and can be accessed directly. In this article, we attempt to understand more about the ‘process’ object and its details with examples. Some of the globules accessible via module inheritance are module, exports, _filename, _dirname, require() etc. setTimeout(), clearTimeout(), setInterval(), clearInterval() - All these can be categorized as timer functions.It wraps the STDIO functionality of a process. console - Console is a module mostly used for logging the information or error.process - Process is a module which provides interaction with the current Node.js process.Setting a property to this namespace makes it accessible throughout the running process. global - It is a namespace and accessible across the application.There are also some which are accessible at the module level via module inheritance. Node.js has many in-built global identifiers that are available and known to developers. Many of the accessible global methods are actually wrappers around methods which make calls to core C libraries. Node.js is built using C++ program with a V8 engine embedded in it to provide an environment to execute JavaScript outside the browser.











Nodejs process