In an exercise for school, there is a website with multiple .js files
The objective of this particular exercise is to get the value of an input field, which is a last name, and compare it to a pre-defined database for autocompletion.
I have to modify file1.js, where I have created a variable that selects the correct input field... I know how to access the string.
Once I have the string, I have to compare it to a known database for any possible Last-name matches... the function is already defined in another file (file2.js), and it looks somewhat like this
server.get("/find_relative/:lastName", (req, res) => {
let lastName = zahteva.params.lastName;
findCustomerByLastName(lastName, (error, customer) => {
if (error) {
console.log(error);
res.end();
} else {
res.send(customer);
}
});
});
I'm not quite sure how to use this function in file1.js, because it's not defined as a variable of any kind... Can anyone help me understand?
Thank you
It looks to me like your code in file2.js is some kind of Node.js server code. I think you're expected to make a GET request like this (lastName is defined as the URL parameter): localhost:8888/find_relative?lastName=Smith.
For making GET/POST/other requests one standard way is to use the Fetch API.