在Node.js中编写文件 [英] Writing files in Node.js

查看:152
本文介绍了在Node.js中编写文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用Node.js找到写入文件的方法,但没有成功。我怎么能这样做?

I've been trying to find a way to write to a file when using Node.js, but with no success. How can I do that?

推荐答案

filesystem API 。最常见的方式是:

const fs = require('fs');
fs.writeFile("/tmp/test", "Hey there!", function(err) {
    if(err) {
        return console.log(err);
    }

    console.log("The file was saved!");
}); 

这篇关于在Node.js中编写文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆