Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

create and save xml file in javascript

/*
There is no way to let Javascript directly create/edit files since it presents a massive security problem.
But it can only read them.

Meanwile at node.js(still js in practicality but for servers), you can do both but you need to understand how it works to fully use it.
*/

// JS(Read Only)

let jsrefstring;
document.getElementById('test_1')
            .addEventListener('change', function() {
            var fr=new FileReader();
            fr.onload=function(){jsrefstring = (fr.result).toString();}
            fr.readAsText(this.files[0]);
        });
       
       
//node.js, read only
const fs = require("fs");
fs.readFileSync("test.txt");


//node.js, overwrite
const fs = require("fs");

fs.open('test.txt', 'test', function (err, file) {if (err) throw err;});


// node.js, add new characters to file
const fs = require("fs");
fs.readFileSync("test.txt", "utf8"); 
fs.appendFile("test.txt", "test", function (err){ if (err) {throw err;}
}) 
Comment

PREVIOUS NEXT
Code Example
Javascript :: array indexof 
Javascript :: js str split 
Javascript :: req is not defined 
Javascript :: The Lodash Array Remove Method 
Javascript :: js regular expression 
Javascript :: tinymce react 
Javascript :: react navbar responsive 
Javascript :: gsap react 
Javascript :: how to detect click outside input element javascript 
Javascript :: express example 
Javascript :: Computed Property 
Javascript :: word table to json 
Javascript :: charat javascript 
Javascript :: javascript date range 
Javascript :: ArduinoJson.h 
Javascript :: how to rerender a page in React when the user clicks the back button 
Javascript :: post requests javascript 
Javascript :: cookie-parser get cookie 
Javascript :: anonymous functions in javascript 
Javascript :: for loop in javacript 
Javascript :: javascript reducer 
Javascript :: javascript pass this to callback 
Javascript :: dependency list useeffect 
Javascript :: samoglasnici-vowels 
Javascript :: react admin data provider 
Javascript :: javascript unit testing frameworks 
Javascript :: nodejs cluster 
Javascript :: js 2d array includes 
Javascript :: last value of array 
Javascript :: difference between =, == and === in javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =