search
LoginSignup
33
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

updated at

node.jsでファイル出力

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);
}

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
What you can do with signing up
33
Help us understand the problem. What are the problem?