Fs模块错误

时间:2016-10-25 07:45:09

标签: javascript node.js

我正在尝试使用Node v6.7.0尝试使用'fs'模块,但是如下所示存在错误。我曾尝试安装它,但不工作(即使我添加整个路径)。如果我在网站https://www.npmjs.com/package/fs办理登机手续,您可以看到该消息。任何想法如何使用该模块?

var filename = process.argv[2];
var version = process.argv[3];
var fs = require('fs');
var prompt = require('C:/Program Files/nodejs/node_modules/prompt');
var p4 = require('C:/Program Files/nodejs/node_modules/p4');



p4.edit(filename, function(err, data) {
    if (err) {
        console.error(err.message);
    }
     fs.readFile(filename, 'utf8', function (err, data) {
        if (err) {
            return console.log(err);
        }
        var result = data.replace(/string to be replaced/g, version);

        fs.writeFile(filename, result, 'utf8', function (err) {
            if (err) return console.log(err);
        });
    });
   console.log(data);

    prompt.start();
    prompt.get('p4 submit -c changelist', function (err, result) {
        if(err) {
            console.log(err.message);
        }
        console.log(result);
    });
});

fs.js:303
  binding.open(pathModule._makeLong(path),
          ^

TypeError: path must be a string or Buffer
    at TypeError (native)
    at Object.fs.readFile (fs.js:303:11)
    at C:\WorkSpace\http.js:22:9
    at C:\Program Files\nodejs\node_modules\p4\p4.js:13:24
    at ChildProcess.exithandler (child_process.js:213:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)

Process finished with exit code 1

2 个答案:

答案 0 :(得分:1)

fs是nodejs核心模块:这里是the fs documentation

答案 1 :(得分:0)

我找到了它应该在节点命令行和var filename = process.argv [2]中执行的答案;必须填补。