Reputation: 1
I need to compare 2 company names, one is from a text file, the other from databases. I import a licence in txt file and if the names are different, a notification on page will pop up asking if I want to rename it (new name will be saved in database).
In JavaScript React, I have to write code that can read a text file, specifically one line from it. This line contains the name of the company that I need to compare with the second name which is in the database.
const handleDispalyDialogButtonClick = () => {
if (nametxt! == namedatabase) {
setDisplayDialog(true)
}
handleImportButtonClick();
};
nametxt
is to be the name of the company in the text file. This name needs to be imported somehow and assigned to nametxt
.
[license]
lic_base=xxxx
lic_nip=xxxx
PC_Nazwa1=name of the company1
PC_Nazwa2=name of the company2
PC_Nazwa3=name of the company3
For example it's like Car=BMW
.
Does anyone have a solution how to make a code which gonna import information, and assign it?
Upvotes: 0
Views: 913
Reputation: 392
You need to put the file you want in your public
folder and just fetch it:
fetch('/path/to/the/file').then((response) => response.text())
.then((data) => {
// read file lines here
const fileLines = data.split('\n')
// find the value you are looking for and compare it to the value you get from the database
}
Also, the screenshot you shared looks like a TOML file, you might want to parse that with TOML Parser to make things easier.
For the value on the database, you cannot directly interact with a database from your code. You need to have an extra layer like an API and request the data from there.
Upvotes: 1