Basic file read


#1

hello,
im a beginner with electron, have some experience with javascript, basic stuff with node

am trying to read a file to a variable, i can work it from there
tried many examples, didnt work,
intend to use renderer process/index.html, if i understand correctly
i tested mini-code-editor example, but there are too many files, i want the most basic stuff without any frameworks or jquery

if someone can post example of, index.html and other changes i need to make, it would be greatly appreciated

on many examples i read, examples werent working, i assume deprecated version, any suggestions for current working examples are also welcome

thank you


#2

hi zpimp,

use fs. And always keep in mind, with electron you have basically all node functionalities.
https://nodejs.org/api/fs.html

const fs = require("fs");

// Asynchronous read
fs.readFile('input.txt', function (err, data) {
  if (err) {
    return console.error(err);
  }
  console.log("Asynchronous read: " + data.toString());
});

// Synchronous read
var data = fs.readFileSync('input.txt');
console.log("Synchronous read: " + data.toString());
console.log("Program Ended");

additionally you may want to have a look on http://electron.atom.io/docs/api/file-object/

hope it helps,
ca333


#3

I’m new here,can you tell me what is electro?
The translator tells me it is the same meaning as electricity.
Thank you.


#4

An electron is a negatively charged subatomic particle that can move between atoms, and their movement creates electrical force.

The Electron framework was developed to support the Atom editor and has since taken on a life of its own as the basis for many apps.


#5

Oh, it is a javascript framework ,I see,thank you.
By the way, has your problem been solved and which country are you in ?
See you tomorrow,I’m off work now…


#6

(This is not on-topic for this thread, so you should have created a new one to ask your question.)

Electron basically acts as a browser for web apps to run inside, with Node built in.


#7

Moring,sorry for asking so many useless questions and interrupting,have a nice day.:slight_smile:


#8

You haven’t interrupted anything. In the future, just create a new thread so that readers don’t get confused.


#9

You are confused with my post or one of my words? Is there any misunderstanding ?


#10

I’m not confused. But this discussion does not have anything to do with the original topic of this thread.


#11

Indeed, at first I thought you were the owner of this topic, then I found wrong, ha ha, so embarrassed.

I found some in CSDN problem helpful advice, feeling learned a lot, and thank you very much, after all, this is my first time to chat with a foreigner on the discuss.:joy:


#12

It works for me !!! Thank you, @ca333.