kai0
kai0

Reputation: 47

Fs Module error

I'm using Node v6.7.0 trying to use 'fs' module but there is error as you see below. i Have tried to install it in addition but is not working(even if i add whole path). If i check in the site https://www.npmjs.com/package/fs you can see the message. Any ideas how can use the module?

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

Upvotes: 0

Views: 1229

Answers (2)

kai0
kai0

Reputation: 47

I found the answer it should be executed in node command line and var filename = process.argv[2]; must be filled up.

Upvotes: 0

mJehanno
mJehanno

Reputation: 866

fs is a nodejs core module : here is the fs documentation

Upvotes: 1

Related Questions