55
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

node.jsでファイル出力

Last updated at Posted at 2017-05-13

#node.jsでファイル出力
node.jsでファイル出力するには、
標準ライブラリであるfsを読み込みます。

node.js
var fs = require("fs");

var text = "テスト出力";

// 非同期で行う場合
fs.writeFile('out.txt', text, (err, data) => {
  if(err) console.log(err);
  else console.log('write end');
});

// 同期で行う場合
try {
  fs.writeFileSync("テストoutput2.txt", text);
  console.log('write end');
}catch(e){
  console.log(e);
}

55
33
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
55
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?