Reputation: 175
I'm looking for a node js code to read and write in one text file. On guthub I have found a promising script from Arahnoid:
https://gist.github.com/Arahnoid/9925725#file-read-write-file-js
If I try to execute it, I get the error "File is not defined (line 3 ... new file(txt...). I guess, I have to install a npm package. But I don't know which one.
Can anybody give my a hint how I get to run this javascript?
Upvotes: 0
Views: 1340
Reputation: 943510
I guess, I have to install a npm package
You don't. If you needed to install an npm package then the code would include a require
statement trying to load it.
Can anybody give my a hint how I get to run this javascript?
It is completely undocumented code found lying around in the Internet. Stop trying.
If you want to read a file using NodeJS then look at NodeJS' documentation. A basic search will turn up the built in file system api.
var fs = require("fs");
fs.readFile('/etc/passwd', function (err, data) {
if (err) {
throw err;
}
console.log(data);
});
(And there's a matching writeFile
method to go with that).
Upvotes: 2
Reputation: 318
It requires Nodejs Enviroment to run the file.
Resource: http://www.tutorialspoint.com/nodejs/nodejs_file_system.htm
Upvotes: -1