节点对象转节点_节点流程对象说明

节点对象转节点

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.mzph.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 …