Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 8949

Node.js で文字列に改行を入れる

$
0
0

作業メモです。

環境

$node--version
v10.17.0

やりたいこと

Slack に Node.js から Webhook 経由で投稿する際に改行した文字列郡の投稿をしたいがどうやればいいか分からず、少し調べた

やりかた

以下の記事が参考になった

Node.js Tips — Send Message, Adding End of Line, and S3 Uploads

os.EOLで出来るらしく、Mac 上でやってみたら出来た

const os = require("os");

var str = '1';
var str2 = '2';
var res = str + os.EOL + str2
console.log(res);
$node test.js
1
2

OK

Node.js の ドキュメントを見ると

The operating system-specific end-of-line marker.

と書いてあるので恐らく Linux/Windows 上でも動くと思われるが、未確認


Viewing all articles
Browse latest Browse all 8949

Trending Articles