Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 基于axios响应编写文件_Node.js_Axios_Filesystems - Fatal编程技术网

Node.js 基于axios响应编写文件

Node.js 基于axios响应编写文件,node.js,axios,filesystems,Node.js,Axios,Filesystems,我正在使用axios向端点发出请求。 然后,我想得到这个请求并将数据保存在一个名为response.json的文件中。 正在创建文件,但内容将按如下方式保存: [object Object] 这是我的代码: const axios = require('axios'); const filesystem = require('fs'); // Make request using to the api using axios axios.get('http://date.jsontest.c

我正在使用axios向端点发出请求。 然后,我想得到这个请求并将数据保存在一个名为response.json的文件中。 正在创建文件,但内容将按如下方式保存:

[object Object]
这是我的代码:

const axios = require('axios');
const filesystem = require('fs');

// Make request using to the api using axios
axios.get('http://date.jsontest.com/')
    .then(response => {
        // console.log(response.data);
        filesystem.writeFile('response.json', response.data, function (err) {
            console.log(err);
        });
    })
    .catch(err => {
        console.log(err)
    });
怎么了


您必须使用
JSON.stringify(response.data)
来保存,而不仅仅是
response.data

不客气!我是朋友,我是普拉泽(巴西南部)