Click here to Skip to main content
14,449,862 members
Rate this:
Please Sign up or sign in to vote.
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 `${server.id} 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 `${server.id} 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;
		console.log(data.toString());
	})
})
Posted
Updated 9-Feb-20 23:55pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 2

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.
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100