003-nodejs文件写入系统

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_33781658/article/details/83271465

我们来试试nodejs的文件写入系统


---实现文件写入操作---

//1.加载文件操作系统,fs模块
var fs = require('fs');

//2.实现文件写入操作
var msg = 'Hello World';

//3.调用fs.writeFile()进行文件写入
fs.writeFile('./hello.txt', msg , 'utf8', function(err){
    if (err){
        console.log('写文件出错啦'+err);
    }else{
        console.log('ok');
    }
});

打开cmd

运行node hello.js

发现目录下创建了hello.txt并且已经写入内容

猜你喜欢

转载自blog.csdn.net/qq_33781658/article/details/83271465