Api how to use File::read?

Hi everybody,

I need some help about the read method from File class. Basically I just want load a file, read the content and put the content in a new file.

Hereafter my code :

fetch() {
project_path = atom.project.getPaths();

let path2 = project_path[0] + "\\template\\template.md"
const myFile2 = new File(path2);
var text2 = myFile2.read(true);


text2 is not a string with the file content but a promise, how can I get the file content please?

Thank you in advance for your answers!

You can make your function async and use await, or add a then method to use thenresolved value. Look up JS Promises for more on how to use them.

1 Like

MDN has a great introduction to Promises. In this case, Node has already created the Promise for you, so once you retrieve it from myFile2.read(), you just have to tell the Promise what to do when it resolves:

myFile2.read(true).then( (text2) => {