Windows上的Node.js根目录在哪里?

时间:2017-07-04 13:55:54

标签: node.js

这是我的Node.js代码(尝试将console.log转换为文件):

var fs = require('fs');
var util = require('util');

var logFile = fs.createWriteStream('/tmp/test', { flags: 'a' });

// Or 'w' to truncate the file every time the process starts.
var logStdout = process.stdout;

console.log = function () {
    logFile.write(util.format.apply(null, arguments) + '\n');
    logStdout.write(util.format.apply(null, arguments) + '\n');
}
console.error = console.log;

我的问题:我找不到这个神秘的/ tmp / test文件夹。

1 个答案:

答案 0 :(得分:1)

Windows上不存在该目录/tmp/test。它只存在于Linux上。将其替换为Windows上实际存在的路径。比如C:/file.txt

您可能希望在创建文件时检查权限和路径。