Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
How to call a function in a server side node file from a client side file

I have a Node.js file that contains a function which writes to local files. I need to call this function from a client side JavaScript file. How can you do this?

I have seen questions about how to call server side functions on an HTML event, but not just strait from a client side script at any time.

Here is the script to write to the local file:

function writeCreateFile(filePath, newValue, callback) {
  checkIfFileExists(filePath, function(exists) {
    if(exists){
      fs.writeFileSync(path.join(__dirname, filePath), newValue, 'utf-8')
    } else {
      fs.appendFileSync(path.join(__dirname, filePath),newValue);
    }
    callback();
  })

}

function checkIfFileExists(filePath, callback) {
  fs.readFile(filePath, 'utf-8', function(err, data) {
   callback(err);
 });
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!