LoginSignup
1
0

More than 3 years have passed since last update.

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

Posted at

作業メモです。

環境

$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 上でも動くと思われるが、未確認

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0