0

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?

3

2 Answers 2

2

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).

Sign up to request clarification or add additional context in comments.

Comments

-1

It requires Nodejs Enviroment to run the file.

Resource: http://www.tutorialspoint.com/nodejs/nodejs_file_system.htm

1 Comment

The code linked from the question won't work in NodeJS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.