1

My externaljsfile.JS looks like this:

"use strict";

const fsLibrary  = require('fs');

function save_installform() {
  alert("Step1");
  fsLibrary.writeFile('/home/pi/newfile.txt', "Hello world.", (error) => {
    alert("Error");
  });
  alert("Written");
};

When calling it with node externaljsfile.js on my raspberry pi it works and creates the text file.

But when including it with src in my HTML server and then calling the function save_installform() with a button, there it only shows "Step 1" as alert like coded and breaks after. No "Error" or "Written" alert and no file.

Is this a permission problem or something like that?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Tim
  • 23
  • 4

1 Answers1

1

fs is a library for nodejs, you cannot use it on client-side. You can lookup for some methods to do so on client, like this: How to create a file in memory for user to download, but not through server?

Viet
  • 12,133
  • 2
  • 15
  • 21