節點對象轉節點_節點流程對象說明

節點對象轉節點

The process object in Node.js is a global object that can be accessed inside any module without requiring it. There are very few global objects or properties provided in Node.js and process is one of them. It is an essential component in the Node.js ecosystem as it provides various information sets about the runtime of a program.

Node.js中的process對象是一個全局對象,可以在任何模塊內對其進行訪問而無需它。 Node.js提供的全局對象或屬性很少, process就是其中之一。 它是Node.js生態系統中的重要組成部分,因為它提供了有關程序運行時的各種信息集。

To explore we will use one of its properties which is called process.versions. This property tells us the information about Node.js version we have installed. It has to be used with -p flag.

為了探索,我們將使用其屬性之一,稱為process.versions 。 此屬性告訴我們有關已安裝的Node.js版本的信息。 它必須與-p標志一起使用。

$ node  -p "process.versions"# output
{ http_parser: '2.8.0',node: '8.11.2',v8: '6.2.414.54',uv: '1.19.1',zlib: '1.2.11',ares: '1.10.1-DEV',modules: '57',nghttp2: '1.29.0',napi: '3',openssl: '1.0.2o',icu: '60.1',unicode: '10.0',cldr: '32.0',tz: '2017c' }

Another property you can check is process.release that is the same as the command $ node --version which we used when we installed Node.js. But the output this time is going to be more detailed.

您可以檢查的另一個屬性是process.release ,它與安裝Node.js時使用的命令$ node --version相同。 但是這次的輸出將更加詳細。

node -p "process.release"# output
{ name: 'node',lts: 'Carbon',sourceUrl: 'https://nodejs.org/download/release/v8.11.2/node-v8.11.2.tar.gz',headersUrl: 'https://nodejs.org/download/release/v8.11.2/node-v8.11.2-headers.tar.gz' }

These are some of the different commands that we can use in a command line to access information that otherwise no module can provide.

這些是我們可以在命令行中使用的一些不同命令,以訪問其他模塊無法提供的信息。

This process object is an instance of the EventEmitter class. It does it contain its own pre-defined events such as exit which can be used to know when a program in Node.js has completed its execution.

process對象是EventEmitter類的實例。 它確實包含自己的預定義事件,例如exit ,可用于了解Node.js中的程序何時完成執行。

Run the below program and you can observe that the result comes up with status code 0. In Node.js this status code means that a program has run successfully.

運行以下程序,您會發現結果顯示為狀態碼0 。 在Node.js中,此狀態代碼表示程序已成功運行。

process.on('exit', code => {setTimeout(() => {console.log('Will not get displayed');}, 0);console.log('Exited with status code:', code);
});
console.log('Execution Completed');

Output of the above program:

上面程序的輸出:

Execution Completed
Exited with status code: 0

Process also provides various properties to interact with. Some of them can be used in a Node application to provide a gateway to communicate between the Node application and any command line interface. This is very useful if you are building a command line application or utility using Node.js

Process還提供各種屬性進行交互。 其中一些可以在Node應用程序中使用,以提供網關在Node應用程序和任何命令行界面之間進行通信。 如果您要使用Node.js構建命令行應用程序或實用程序,這將非常有用

  • process.stdin: a readable stream

    process.stdin:可讀流
  • process.stdout: a writable stream

    process.stdout:可寫流
  • process.stderr: a wriatable stream to recognize errors

    process.stderr:可識別錯誤的可寫流

Using argv you can always access arguments that are passed in a command line. argv is an array which has Node itself as the first element and the absolute path of the file as the second element. From the third element onwards it can have as many arguments as you want.

使用argv您始終可以訪問在命令行中傳遞的參數。 argv是一個數組,其節點本身為第一個元素,文件的絕對路徑為第二個元素。 從第三個元素開始,它可以具有任意數量的參數。

Try the below program to get more insight into how you can use these various properties and functions.

嘗試下面的程序,以更深入地了解如何使用這些各種屬性和功能。

process.stdout.write('Hello World!' + '\n');process.argv.forEach(function(val, index, array) {console.log(index + ': ' + val);
});

If you run the above code with the following command you will get the output and the first two elements are of argv are printed.

如果使用以下命令運行上面的代碼,您將獲得輸出,并打印出argv的前兩個元素。

$ node test.js# output
Hello World!
0: /usr/local/bin/node
1: /Users/amanhimself/Desktop/articles/nodejs-text-tuts/test.js

翻譯自: https://www.freecodecamp.org/news/node-process-object-explained/

節點對象轉節點

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390610.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390610.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390610.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

PAT——1018. 錘子剪刀布

大家應該都會玩“錘子剪刀布”的游戲:兩人同時給出手勢,勝負規則如圖所示: 現給出兩人的交鋒記錄,請統計雙方的勝、平、負次數,并且給出雙方分別出什么手勢的勝算最大。 輸入格式: 輸入第1行給出正整數N&am…

leetcode 1239. 串聯字符串的最大長度

題目 二進制手表頂部有 4 個 LED 代表 小時(0-11),底部的 6 個 LED 代表 分鐘(0-59)。每個 LED 代表一個 0 或 1,最低位在右側。 例如,下面的二進制手表讀取 “3:25” 。 (圖源&am…

flask redis_在Flask應用程序中將Redis隊列用于異步任務

flask redisBy: Content by Edward Krueger and Josh Farmer, and Douglas Franklin.作者: 愛德華克魯格 ( Edward Krueger) 和 喬什法默 ( Josh Farmer )以及 道格拉斯富蘭克林 ( Douglas Franklin)的內容 。 When building an application that performs time-co…

CentOS7下分布式文件系統FastDFS的安裝 配置 (單節點)

背景 FastDFS是一個開源的輕量級分布式文件系統,為互聯網量身定制,充分考慮了冗余備份、負載均衡、線性擴容等機制,并注重高可用、高性能等指標,解決了大容量存儲和負載均衡的問題,特別適合以文件為載體的在線服務&…

如何修復會話固定漏洞_PHP安全漏洞:會話劫持,跨站點腳本,SQL注入以及如何修復它們...

如何修復會話固定漏洞PHP中的安全性 (Security in PHP) When writing PHP code it is very important to keep the following security vulnerabilities in mind to avoid writing insecure code.在編寫PHP代碼時,記住以下安全漏洞非常重要,以避免編寫不…

劍指 Offer 38. 字符串的排列

題目 輸入一個字符串,打印出該字符串中字符的所有排列。 你可以以任意順序返回這個字符串數組,但里面不能有重復元素。 示例: 輸入:s “abc” 輸出:[“abc”,“acb”,“bac”,“bca”,“cab”,“cba”] 限制: 1…

前饋神經網絡中的前饋_前饋神經網絡在基于趨勢的交易中的有效性(1)

前饋神經網絡中的前饋This is a preliminary showcase of a collaborative research by Seouk Jun Kim (Daniel) and Sunmin Lee. You can find our contacts at the bottom of the article.這是 Seouk Jun Kim(Daniel) 和 Sunmin Lee 進行合作研究的初步展示 。 您可以在文章底…

解釋什么是快速排序算法?_解釋排序算法

解釋什么是快速排序算法?Sorting algorithms are a set of instructions that take an array or list as an input and arrange the items into a particular order.排序算法是一組指令,這些指令采用數組或列表作為輸入并將項目按特定順序排列。 Sorts are most c…

SpringBoot自動化配置的注解開關原理

我們以一個最簡單的例子來完成這個需求:定義一個注解EnableContentService,使用了這個注解的程序會自動注入ContentService這個bean。 Retention(RetentionPolicy.RUNTIME) Target(ElementType.TYPE) Import(ContentConfiguration.class) public interfa…

hadoop將消亡_數據科學家:適應還是消亡!

hadoop將消亡Harvard Business Review marked the boom of Data Scientists in their famous 2012 article “Data Scientist: Sexiest Job”, followed by untenable demand in the past decade. [3]《哈佛商業評論 》在2012年著名的文章“數據科學家:最性感的工作…

劍指 Offer 15. 二進制中1的個數 and leetcode 1905. 統計子島嶼

題目 請實現一個函數,輸入一個整數(以二進制串形式),輸出該數二進制表示中 1 的個數。例如,把 9 表示成二進制是 1001,有 2 位是 1。因此,如果輸入 9,則該函數輸出 2。 示例 1&…

[轉]kafka介紹

轉自 https://www.cnblogs.com/hei12138/p/7805475.html kafka介紹1.1. 主要功能 根據官網的介紹,ApacheKafka是一個分布式流媒體平臺,它主要有3種功能: 1:It lets you publish and subscribe to streams of records.發布和訂閱消…

如何開始android開發_如何開始進行Android開發

如何開始android開發Android開發簡介 (An intro to Android Development) Android apps can be a great, fun way to get into the world of programming. Officially programmers can use Java, Kotlin, or C to develop for Android. Though there may be API restrictions, …

httpd2.2的配置文件常見設置

目錄 1、啟動報錯:提示沒有名字fqdn2、顯示服務器版本信息3、修改監聽的IP和Port3、持久連接4 、MPM( Multi-Processing Module )多路處理模塊5 、DSO:Dynamic Shared Object6 、定義Main server (主站點) …

leetcode 149. 直線上最多的點數

題目 給你一個數組 points ,其中 points[i] [xi, yi] 表示 X-Y 平面上的一個點。求最多有多少個點在同一條直線上。 示例 1: 輸入:points [[1,1],[2,2],[3,3]] 輸出:3 示例 2: 輸入:points [[1,1],[3,…

solidity開發以太坊代幣智能合約

智能合約開發是以太坊編程的核心之一,而代幣是區塊鏈應用的關鍵環節,下面我們來用solidity語言開發一個代幣合約的實例,希望對大家有幫助。 以太坊的應用被稱為去中心化應用(DApp),DApp的開發主要包括兩大部…

2019大數據課程_根據數據,2019年最佳免費在線課程

2019大數據課程As we do each year, Class Central has tallied the best courses of the previous year, based on thousands of learner reviews. (Here are the rankings from 2015, 2016, 2017, and 2018.) 與我們每年一樣,根據數千名學習者的評論, …

2017-12-07 socket 讀取問題

1.用socke阻塞方式讀取服務端發送的數據時會出現讀取一直阻塞的情況,如果設置了超時時間會在超時時間后讀取到數據: 原因:在不確定服務器會不會發送 socket發送的數據不會返回null 或者-1 所以用常規的判斷方法是不行的。 解決辦法有兩個:1 …

靜態代理設計與動態代理設計

靜態代理設計模式 代理設計模式最本質的特質:一個真實業務主題只完成核心操作,而所有與之輔助的功能都由代理類來完成。 例如,在進行數據庫更新的過程之中,事務處理必須起作用,所以此時就可以編寫代理設計模式來完成。…

svm機器學習算法_SVM機器學習算法介紹

svm機器學習算法According to OpenCVs "Introduction to Support Vector Machines", a Support Vector Machine (SVM):根據OpenCV“支持向量機簡介”,支持向量機(SVM): ...is a discriminative classifier formally defined by a separating …