javascript - Fs 模块错误

标签 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

最佳答案

fs 是一个 Nodejs 核心模块:这里是 the fs documentation

关于javascript - Fs 模块错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40234178/

相关文章:

javascript - 使用 isNaN(foo) 和 typeof foo !== number 时,.forEach 返回意外结果

javascript - 在 jQuery 中将 DIV 中的第一个子元素作为 UL 元素进行操作

node.js - 如何在NodeJS中读取大文件?

java - 使用nodejs模拟soapUI签名请求

javascript - Node JS 能否提示 HTML 页面发生变化?

javascript - 需要帮助声明具有不同名称的数组,JavaScript

javascript - Internet Explorer 光标 : auto

javascript - D3 旋转地球仪 : How to rotate the graticule (grid)?

javascript - 自定义 JSON.stringify 无法将对象作为一个整体进行字符串化,但在迭代一层时有效

node.js - 类型错误 : userDB is not a constructor