Click here to Skip to main content
15,668,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So I am trying to learn javascript, but I cannot find a tutorial that will allow me to search a text file using a string.

I am wanting to search a text file at:
constant path = "./data/data.txt"

And I want to search for `${} prefix: `
I would then want to store the full line (as that's only most of the line, I want the full thing) as a variable, but I want to then remove `${} prefix: ` from the variable so all I have left is what I want to deal with. Any possible way for this to happen?

What I have tried:

The most I could do was this:
client.on("guildDelete", (guild) => {
	fs.readFile( path, (err, data) => {
		if (err) throw err;
Updated 11-Apr-20 1:36am

1 solution

You can't read files using javascript. If you google how to use the html5 file api you'll find lots of examples of accessing files via the "file" input component, but that requires the user to explicitly select the file to be searched through.

This is for security reasons so no point in asking if it can be done another way.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900