Write .txt file node.js

4

I need to generate a txt file with some information and save it in C: How can I do this using node.js?

    
asked by anonymous 30.06.2017 / 20:28

1 answer

3

Using the filesystem API of the NodeJS.

The API has a lot of detail and gives you endless possibilities, read the documentation > for more details.

Remember that permission is required to write to the folder.

A very simple example.

var fs = require('fs');

fs.writeFile("C:\Pasta\meuarquivo.txt", "Hello, txt!", function(erro) {

    if(erro) {
        throw erro;
    }

    console.log("Arquivo salvo");
}); 
    
30.06.2017 / 20:34