I have an electron project when I need to get electron to read a local file.
Right now what I have is this, where it loads and displays the contents of a html file.
I just need it to read a file and store it on a variable for now.
Here is my current main.js:
const {app, BrowserWindow } = require('electron');
const path = require('path');
const url = require('url');
var fs = require('fs');
let mainWindow;
function createNewWindow() {
mainWindow = new BrowserWindow({
width: 1300,
height: 1000,
minWidth: 600,
minHeight: 400,
title: 'Test App'
})
}
function loadInitialUrl() {
mainWindow.loadURL(url.format({
pathname: path.join(__dirname, 'index.html'),
protocol: 'file:',
slashes: true
}))
}
function closeApplication() {
mainWindow.on('closed', () => {
mainWindow = null;
})
}
app.on('ready', function(){
createNewWindow();
loadInitialUrl();
mainWindow.setMenu(null);
mainWindow.openDevTools();
fs.readFile('./README.md', 'utf8', function (err,data) {
if (err) {
return console.log(err);
}
console.log(data);
});
mainWindow.on('closed', function() {mainWindow = null;});
});
How can I do this as it's not showing the contents of the README.md file in the console.log
path
is correct. what is the current output of log? – Masurium