I want to read a file with commander:
#!/usr/bin/env node
var fs = require('fs')
var program = require('commander')
program
.version('0.0.1')
.usage('<keywords>')
.parse(process.argv)
if(!program.args.length) {
program.help()
} else {
var filename = program.args
console.log('keys: ' + filename)
fs.readFile(filename, 'utf8', function(err, data) {
if (err) throw err
console.log(data)
})
}
$ ./m2k.js test.txt
However, I get the this error:
fs.js:430
binding.open(pathModule._makeLong(path),
^
TypeError: path must be a string
What am I doing wrong?
(I have a file called test.txt in the same folder as m2k.js.)
Aucun commentaire:
Enregistrer un commentaire