I am trying to read XML file by browsing in local machine using input.
Here is my code
import React from "react";
import "./App.css";
import * as fs from "fs";
var parseString = require("xml2js").parseString;
const fileToParse =
"file:///Users/apple/Documents/Project assignments/NewCCD/Ahmed.xml";
function App() {
const getPath = (e) => {
fs.readFile(fileToParse, function (err, data) {
parseString(data, function (err, result) {
console.log(result);
});
});
};
return (
<div>
<input type="file" title="Browse" onChange={getPath} />
</div>
);
}
Here I am using the exact path still couldn't able to read file and getting this error.
TypeError: fs__WEBPACK_IMPORTED_MODULE_3__.readFile is not a function