Node.js writeStream.columns 属性
writeStream.columns属性是 tty 模块中 WriteStream 类的内置应用程序编程接口,用于获取此写入 Stream 对象具有的列数。
句法:
const writeStream.columns
返回值:此属性返回此写入 Stream 对象包含的列数。
示例 1:文件名:index.js
Javascript
// Node.js program to demonstrate the
// writeStream.columns 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");
// Catching the message event
server.on("message", function (msg) {
// Creating and initializing a
// WriteStream object
let WriteStream = process.stdout;
// Getting number of columns
// by using columns API
const col = WriteStream.columns;
// 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 Columns :- ",
0, 21, 1234, "localhost");
Javascript
// Node.js program to demonstrate the
// writeStream.columns property
// Creating and initializing a WriteStream object
let WriteStream = process.stdout;
// Getting number of columns
// by using columns API
const col = WriteStream.columns;
// Displaying the result
console.log("Number of Columns :- " + col);
输出:
Number of Columns :- 182
示例 2:文件名:index.js
Javascript
// Node.js program to demonstrate the
// writeStream.columns property
// Creating and initializing a WriteStream object
let WriteStream = process.stdout;
// Getting number of columns
// by using columns API
const col = WriteStream.columns;
// Displaying the result
console.log("Number of Columns :- " + col);
输出:
Number of Columns :- 182
使用以下命令运行 index.js 文件:
node index.js
参考: https://nodejs.org/dist/latest-v12.x/docs/api/tty.html#tty_writestream_columns