当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js writeStream.rows用法及代码示例


writeStream.rows属性是tty模块中WriteStream类的内置应用程序编程接口,该接口用于获取此write Stream对象具有的行数。

用法:

const writeStream.rows

参数:此属性不包含任何参数。

返回值:此属性返回此写入Stream对象具有的行数。

范例1: 文件名:index.js



// Node.js program to demonstrate the 
// writeStream.rows property 
  
// Importing dgram module 
var dgram = require('dgram'); 
  
// Creating and initializing client 
// and server socket 
var client = dgram.createSocket("udp4"); 
var server = dgram.createSocket("udp4"); 
  
// Handling the message event 
server.on("message", function (msg) { 
  
  // Creating and initializing a 
  // WriteStream object 
  let WriteStream = process.stdout; 
  
  // Getting number of rows 
  // by using rows API 
  const col = WriteStream.rows; 
  
  // Displaying the result 
  process.stdout.write(msg + col); 
  
  // Exiting process 
  process.exit(); 
}) 
// Binding server with port 
.bind(1234, () => { 
}); 
  
// Client sending message to server 
client.send("Number of rows:- ", 
        0, 21, 1234, "localhost");

输出:

Number of rows:- 10

范例2: 文件名:index.js

// Node.js program to demonstrate the 
// writeStream.rows property 
  
// Creating and initializing a 
// WriteStream object 
let WriteStream = process.stdout; 
  
// Getting number of rows 
// by using rows API 
const col = WriteStream.rows; 
  
// Displaying the result 
console.log("Number of rows:- " + col);

使用以下命令运行index.js文件:

node index.js

输出:

Number of rows:- 10

参考:https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_rows




相关用法


注:本文由纯净天空筛选整理自RohitPrasad3大神的英文原创作品 Node.js writeStream.rows Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。