我有以下javascript:
#!/usr/bin/env node
var fs = require(’fs’);
var outfile = "hello.txt";
var out = "Modify this script to write out something different.\n";
fs.writeFileSync(outfile, out);
console.log("Script: " + __filename + "\nWrote: " + out + "To: " + outfile);
执行以下命令:
node test.js
cat hello.txt
我得到以下输出:
[object Object]
我做错了什么?
答案 0 :(得分:0)
您将对象作为字符串返回。您需要找出对象具有哪些属性并返回它们,或者遍历对象并显示属性,或将其转换为字符串......
console.log(JSON.stringify(objToJson));