Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day, Please i am new to javascript and i want to save the results calculated on an html in a text file using javascript.
i don't really know how to implement it.
The webpage has java code calculate some numbers and before displaying it in page it has 'return' in its code so i put my lame code before it and some times it displays well while sometimes the page just shows blank.
Please what i want to do is for the website to save all results in a text file. that is it appends to the file.
My code is not correct i know because i am just new to it. so should i place it before the return command in the code?

What I have tried:

JavaScript
const dir = dirname('C:/Users/user/Desktop/WOW');

  if (!existsSync(dir)) {
    mkdirSync(dir, { recursive: true });
    core.debug(`Created directory: ${dir}`);
  }
var jj = sa + p(trimmed) + ea + " ".repeat(addr.length-trimmed.length);
const fs = require('fs')
const filePath = 'file.txt'
 fs.appendFile(filePath, jj, (err) => {
  })
Posted
Updated 3-Apr-20 22:17pm
v2
Comments
Richard MacCutchan 4-Apr-20 4:05am    
You cannot access the client file system from Javascript.

1 solution

JavaScript do not have access to client file system, it is for security/safety reasons.
Access to client file system is a dream feature for any malware.
What is possible is local storage, it is a protected storage space which does not expose client file system.
HTML Web Storage[^]
[Update]
Quote:
This is wrong. Then how come Flowchart Maker & Online Diagram Software[^] can save and modify the files to folder when Device is chosen ?

The site sends file just like any donwloads and the browser asks me what I want to do with it, save or open it.
The JS of this site does not write directly in my file system.
 
Share this answer
 
v2
Comments
MadMyche 4-Apr-20 9:17am    
+5
Patrice T 4-Apr-20 9:51am    
Thank you
Yesudass Moses 14-Mar-21 8:21am    
This is wrong. Then how come https://app.diagrams.net/ can save and modify the files to folder when Device is chosen ?
Patrice T 14-Mar-21 9:09am    
See update in solution.
Richard MacCutchan 14-Mar-21 9:41am    
It can only save to the local device by the user selecting the location. It cannot do it without user action.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900